I came up with this:
- tye (but my friends call me "Tye")my $beg= ""; # Beginning of new string my $end= ""; # Ending of new string my $prev= ""; # Previous token my $str= "'a1b1a2b1b2a3b1b2b3'db1b2"; for my $sub ( split /([ab]\d+)/, $str ) { next if "" eq $sub; if( $prev =~ /^a/ && $sub =~ /^b/ ) { $end .= "($sub)"; } else { $beg .= $sub; } $prev= $sub; } print "$beg$end\n";
In reply to (tye)Re: Real global substitution, what's the best way?
by tye
in thread Real global substitution, what's the best way?
by mirod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |