in reply to changing only the first two matches of a regex
Here is a fun (and powerful) way to only do some substitutions:
Though I'd probably use one of the other solutions mentioned in this particular case. - tye (but my friends call me "Tye")my $str= "1_abc/2_def/bla_30_31_blah"; my $count= 0; while( $str =~ /\d+_/g ) { last if 2 < ++$count; $str =~ s///; } print "\$str=($str)\n"; # $str=(abc/def/bla_30_31_blah)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: changing only the first two matches of a regex
by merlyn (Sage) on Mar 20, 2001 at 23:30 UTC | |
by tye (Sage) on Mar 20, 2001 at 23:47 UTC |