in reply to Re^3: Modifying the match position after each match
in thread Modifying the match position after each match
I think (mostly because I've only been following this thread from the sidelines) that this won't "work" if there is no underscore at the end of the string:
#! /usr/bin/perl -w use strict; use locale; for my $s ( @{[ "_'nada_komo_el_'sol_", "_na'da_komo_el_so'l_", "_na'da_komo_el_sol" ]} ) { print $s; $s =~ s/(_)([^'][^_]+?)/$1'$2/g; print " : $s\n"; } __END__ > perl -w tmp.pl _'nada_komo_el_'sol_ : _'nada_'komo_'el_'sol_ _na'da_komo_el_so'l_ : _'na'da_'komo_'el_'so'l_ _na'da_komo_el_sol : _'na'da_'komo_'el_'sol
My solution would be to use a zero-width lookahead to ensure but not match the following underscore:
$s =~ s/(_)([^_']+?)(?=_)/$1'$2/g;
... but again, as I haven't been closely following, I'm not sure where my approach will fail the specifications.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Modifying the match position after each match
by BrowserUk (Patriarch) on Mar 24, 2010 at 13:29 UTC |