in reply to Re^3: Can you assign to pos() in a s/foo/bar/g
in thread Can you assign to pos() in a s/foo/bar/g
I'm not sure you need the complication of oha's method here as it depends on the fact that the left side of the alternation will still match once you have done the first substitution whereas in your problem it won't. Using just a capture group seems to work.
$ perl -E ' > $_ = q{Bla class="x1" class="x2" class="x3" Blabla}; > say; > s{" class="([^"]+)}{ $1}g; > say;' Bla class="x1" class="x2" class="x3" Blabla Bla class="x1 x2 x3" Blabla
Attacking the problem from (literally) a different direction would be another way of achieving the same result without a capture group.
$ perl -E ' > $_ = q{Bla class="x1" class="x2" class="x3" Blabla}; > say; > $r = reverse $_; > $r =~ s{"=ssalc "}{ }g; > $_ = reverse $r; > say;' Bla class="x1" class="x2" class="x3" Blabla Bla class="x1 x2 x3" Blabla $
I hope this is helpful.
Cheers,
JohnGG
Update: I forgot to mention, double-quotes are not regex metacharacters so they don't need to be escaped.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Can you assign to pos() in a s/foo/bar/g
by Jaikov (Initiate) on Feb 25, 2010 at 23:21 UTC |