Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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?

What's my password?
Create A New User
[Corion]: Also suffering is my 2-factor Github sign-in, as now, FF can't read my USB token anymore. "This was a horrible idea" is slowly dawning on me ;)
[Corion]: Yay. FF now has u2f built-in (behind an about:config setting), so using an USB token to sign in actually works :)
[Corion]: So, it's not all bad with the new FF :)
[holli]: 2factor is a bit too much for me. i just use passwords like jhbn8789q27312laks dmaw98^
[moritz]: isn't there also some about:config setting to enable the old plugin API?
[Discipulus]: indeed, only the logo is nicer

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2017-11-20 20:19 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (293 votes). Check out past polls.