Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I'm new to Perl and trying to figure out how to only replace matches after the initial match using regex. For example, I would like to replace any matches of bar with foo after finding the first bar.
Input foofoo
Output foobar
I have tried what I believe is look ahead assertion
$s = s/bar(?=bar)/foo/;
However it seems to get rid of everything and print an empty string.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex match and replace
by kennethk (Abbot) on Mar 04, 2015 at 17:39 UTC | |
by Anonymous Monk on Mar 04, 2015 at 22:25 UTC | |
|
Re: Regex match and replace
by AnomalousMonk (Archbishop) on Mar 04, 2015 at 18:04 UTC | |
by Anonymous Monk on Mar 04, 2015 at 22:26 UTC | |
|
Re: Regex match and replace
by hdb (Monsignor) on Mar 04, 2015 at 21:10 UTC | |
by Anonymous Monk on Mar 04, 2015 at 22:30 UTC | |
|
Re: Regex match and replace
by choroba (Cardinal) on Mar 05, 2015 at 09:20 UTC |