cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
This yields the following$text = "U.S. Army\nthe Army has been berry-berry good to me\nUS-Army\ +nUS Army\n"; $text =~ s/\bArmy\b|U\.S\. Army/US-Army/g;
The last two entries are obviously not what I want and they are happening because the dash counts as a boundary. This is even worse in the context of a loop likeUS-Army the US-Army has been berry-berry good to me US-US-Army US US-Army
which results in an infinite loop. So my question is: How can I get the dash to not count as a boundary character? (because of external constraints, it's not possible to use another joining character).while ($text =~ s/\bArmy\b|U\.S\. Army/US-Army/g) { print "$text\n\n"; }
Many thanks in advance...
Steve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regexp dashes at boundaries
by brian_d_foy (Abbot) on Mar 17, 2005 at 22:42 UTC | |
by cormanaz (Deacon) on Mar 21, 2005 at 22:29 UTC | |
by brian_d_foy (Abbot) on Mar 24, 2005 at 18:43 UTC | |
|
Re: Regexp dashes at boundaries
by Roy Johnson (Monsignor) on Mar 18, 2005 at 12:47 UTC | |
|
Re: Regexp dashes at boundaries
by crashtest (Curate) on Mar 17, 2005 at 22:10 UTC | |
by tlm (Prior) on Mar 17, 2005 at 23:22 UTC | |
by ww (Archbishop) on Mar 18, 2005 at 15:25 UTC | |
by cormanaz (Deacon) on Mar 17, 2005 at 22:33 UTC | |
|
Re: Regexp dashes at boundaries
by sh1tn (Priest) on Mar 18, 2005 at 18:35 UTC |