Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: regexp - repeatedly delete words expressed in alternation from end of string

by Roy Johnson (Monsignor)
on Nov 06, 2007 at 17:42 UTC ( [id://649285]=note: print w/replies, xml ) Need Help??


in reply to Re: regexp - repeatedly delete words expressed in alternation from end of string
in thread repeatedly delete words expressed in alternation from end of string [regexp]

Should only remove the expression from the end of the string. So it's actually a little simpler:
my @words = qw( SA NV LTD CO LLC ); my ($re) = map qr/$_/i, join '|', map quotemeta, @words; while (<DATA>) { chomp; s/(?:\s*\b$re)+$//; print "[$_]\n"; } __END__ Bobs leave SA Warehouse SA LTD Jims Fine Wines CO LLC

Caution: Contents may have been coded under pressure.
  • Comment on Re^2: regexp - repeatedly delete words expressed in alternation from end of string
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found