Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Substitute _last_ occurence in string?

by PrakashK (Pilgrim)
on Jul 25, 2001 at 18:40 UTC ( #99692=note: print w/ replies, xml ) Need Help??


in reply to Substitute _last_ occurence in string?

s/(two )(?!.*two )//
Probably valid only perl 5.6.0 +. Update: Above works only if two is followed by a space. It fails if:
$string = "one two three two four two";
The following works. Also, the parentheses around the first two are unnecessary.
$string =~ s/two\s*(?!.*two)//


Comment on Re: Substitute _last_ occurence in string?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-09-21 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls