in reply to Re^2: 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 have a similar problem but could not get oha's solution to work...
Problem: I have big files in which all appearances of following class-Attributes shall be shortened like so:
Bla class="x1" class="x2" class="x3" Blabla
==> Bla class="x1 x2 x3" Blabla
With the substitution
the result is:
==> Bla class="x1 x2" class="x3" Blabla
A loop delivers of course the correct result:
But because the substitution would need several passes to get the result this is not my prefered way.
I would like to have an option, that the substitution is starting again at the position right before the replacement and not after the replacement.
I have tried several times to use \G in the substitution like this one:
or
s/\G\s*class=\"([^\"]*)\"\s*class=\"([^\"]*)\"\s*/ class="$1 $2" / while /\s*class=\"([^\"]*)\"\s*class=\"([^\"]*)\"\s*/g;but to no success.
Any Idea, to manage this substitution with one pass?
PS: in oha's example there is a little error if the string starts with _ as f.e. $_ = q{_FR7234C__A_B_C_Bonzo_Dog_D_B};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Can you assign to pos() in a s/foo/bar/g
by johngg (Canon) on Feb 25, 2010 at 14:39 UTC | |
by Jaikov (Initiate) on Feb 25, 2010 at 23:21 UTC |