Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by tye (Sage)
on Oct 30, 2001 at 01:19 UTC ( #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? - Answer 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

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2017-09-21 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (251 votes). Check out past polls.

    Notices?