in reply to Regexp dashes at boundaries
You don't always need alternation, especially if most of the stuff on either side is the same. You can use the ? quantifier to denote some parts as optional.
This example works for the input you showed, but other forms you might find might require it to change a bit.
#!/usr/bin/perl $text = <<"HERE"; U.S. Army the Army has been berry-berry good to me US-Army US Army HERE $text =~ s/(?:U.?S.?[\s-])*Army/US-Army/g; print $text;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regexp dashes at boundaries
by cormanaz (Deacon) on Mar 21, 2005 at 22:29 UTC | |
by brian_d_foy (Abbot) on Mar 24, 2005 at 18:43 UTC |