in reply to Need help with substitue /g
Rather than a repeated global match you could capture what's inside the second set of parentheses and then use split, map and join to modify it in one go. (Note that I use the hex value for a single quote because I am running this as a one-liner in a *nix shell; you wouldn't need to do that inside a script.)
$ perl -E ' > $_ = q{(1,2,3) xxx (1,2,3)}; > s{([^(]+)(?=\)$)}{ join q{,}, map qq{\x27$_\x27}, split m{,}, $1 }e; > say;' (1,2,3) xxx ('1','2','3') $
I hope this is of interest.
Cheers,
JohnGG
|
|---|