Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 ( #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
Node Status?
node history
Node Type: note [id://649285]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2019-11-15 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (82 votes). Check out past polls.

    Notices?