cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to process some text to consistently tokenize references to people. I am using the following regexp to do this for Condoleeza Rice:
The problem is that this will match the substring "rice" in any old word. I guess I could fix this with anchors or a brute-force enumeration of options. But I'm wondering if there is a more elegant way to rewrite this regexp so the second and third terms function as a non-exclusive or. I other words (whether or not the title is in front of her name) it should match only these cases$text =~ s/(national security adviser )?(dr. |doctor )?(condoleeza )?r +ice/condoleezarice/ig;
doesn't match the first word of items 3 or 4 because the alternation operator | is functioning as an exclusive or. Your advice appreciated.((dr. |doctor )|(condoleeza ))rice
TIA....
Steve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Non-exclusive or in regexp?
by Sidhekin (Priest) on Sep 06, 2004 at 00:48 UTC | |
by tachyon (Chancellor) on Sep 06, 2004 at 02:19 UTC | |
by cormanaz (Deacon) on Sep 06, 2004 at 12:04 UTC | |
by Sidhekin (Priest) on Sep 06, 2004 at 12:34 UTC | |
|
Re: Non-exclusive or in regexp?
by ikegami (Patriarch) on Sep 06, 2004 at 00:39 UTC | |
|
Re: Non-exclusive or in regexp?
by tachyon (Chancellor) on Sep 06, 2004 at 00:55 UTC | |
|
Re: Non-exclusive or in regexp?
by Eimi Metamorphoumai (Deacon) on Sep 06, 2004 at 00:46 UTC | |
|
Re: Non-exclusive or in regexp?
by Zaxo (Archbishop) on Sep 06, 2004 at 00:39 UTC | |
|
Re: Non-exclusive or in regexp?
by sintadil (Pilgrim) on Sep 06, 2004 at 00:38 UTC | |
|
Re: Non-exclusive or in regexp?
by Anonymous Monk on Sep 06, 2004 at 12:08 UTC |