473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Another Regular Expression Question

Here is what i am trying to do:
I have a paragraph of text that I am parsing through looking for specified key words or phrases. The keywords/phrases are contained in an array that I loop through and the keyphrase could be written two ways:
Some: Title or Some Title
Without breaking the keyphrase (becuase it is stored in a variable) before i search the paragraph, how can I, within the same regular expression, do the following
if the keyword is Some: Title, match anything in the paragraph that is either Some Title, or Some: Title
Nov 16 '06 #1
3 1215
Read me: http://perldoc.perl.org/perlretut.ht...ng-repetitions
OK I have a pragraph that looks like this:
---------
Following the Crisis on Infinite Earths story, DC began to reboot all its properties. Uniquely though, most of the Silver Age Batman stories remained canon, with DC only wishing to revisit Batman's early years. The story was followed up by Batman: Year Two, but in the 1994 Zero Hour company wide crossover, it was erased from continuity. Catwoman: Year One (Catwoman Annual #2, 1998) tied into Catwoman's scenes, stating that the character had not been a prostitue, but rather a thief posing as one to help her commit crimes.
--------


I have a list of keywords that I want to highlight in the array:
--------
array("Batman Year Two", "Catwoman Year One");
--------

What I want to do is that when the phrase "Catwoman Year One" OR "Catwoman: Year One" is found in the paragraph I am searching, I want to be able to match on either/both (if both are there) the one containing the ':' and the one without. I want to be able to do this with out breaking the phrase up before hand (say on a ':' ) and compairing every word. Is there a way, with a regular expression to do something like

find all occurences of $someVar (eg, Catwoman Year One), in the paragraph reguardless of wheither or not the version in the paragraph contains a ':'?

Does that make it any clearer?
Nov 17 '06 #3
miller
1,089 Expert 1GB
You'll have to explicitly create the regular expression yourself. The link that I gave you documented the functionality that you specifically need.

Expand|Select|Wrap|Line Numbers
  1. $paragraph =~ s/(Catwoman:? Year One)/"$1"/g;
  2.  
Basically it's the '?' special character for regex's that you need.
Nov 17 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Harlin Seritt | last post by:
I have been looking at the Python re module and have been trying to make sense of a simple function that I'd like to do. However, no amount of reading or googling has helped me with this. Forgive...
10
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
5
by: Ryan | last post by:
HELLO I am using the following MICROSOFT SUGGESTED (somewhere on msdn) regular expression to validate email addresses however I understand that the RFP allows for "+" symbols in the email address...
7
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist -...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.