Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Regular Expression, substitution

by atcroft (Abbot)
on Apr 06, 2016 at 01:44 UTC ( [id://1159668]=note: print w/replies, xml ) Need Help??


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
    Yes that seems like it should work, smashing new bugs but will try that out when I'm done with this new problem. Yes it woks perfectly fine thanks for understanding my poorly written example.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1159668]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found