Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Answer: How do I delete the last instance of a word from a string?

( #121982=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I delete the last instance of a word from a string? contributed by tye

Although I prefer the rindex/substr solution, another alternative involves regular expressions with "zero-width negative look-ahead assertions": s/\Q$word\E(?!.*\Q$word\E)//s
or, if you really only want "words": s/\b\Q$word\E\b(?!.*\b\Q$word\E\b)//s

Comment on Answer: How do I delete the last instance of a word from a string?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-08-28 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls