in reply to changing only the first two matches of a regex
Hint: use anchors.
With your example, it appears you want to get rid of the first two digits and their following underscores that appear in the string. A regex that does that is:
$string =~ s/^\d_(\D+?)\d_(.*)/$1$2/;
the caret "^" at the beginning of this regex anchors things to the beginning of the string. You then make judicious use of captures to get the desired result.
Philosophy can be made out of anything. Or less -- Jerry A. Fodor
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: changing only the first two matches of a regex
by mirod (Canon) on Mar 20, 2001 at 19:54 UTC |