in reply to Regular Expression, substitution
I think your problem in the first regex is the braces ("square brackets") in place of parentheses. When I tried a similar regex, I got the expected results:
$ perl -Mstrict -Mwarnings -le ' my $str = q{This is a test of a regex to remove the words "a", "an", a +nd "the" from a sentence.}; print q{Before: }, $c; $c =~ s/\b(an?|the)\b/gimsx; print q{After: }; ' This is a test of a regex to remove the words "a", "an", and "the" fro +m a sentence. This is test of regex to remove words "", "", and "" from sentence +.
Hope that helps.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular Expression, substitution
by lobs (Acolyte) on Apr 06, 2016 at 02:38 UTC |