in reply to RegExp: pos management in global substitution
Can this be done with s/// operator without e modifier in one approach?
Probably, but its a brainfuckadvanced way to go about it :)
1. After success substitution return to the position where substitution started and try to substitute again...
Not sure , but I don't think you can without /e
Here is my non working advanced attempt
I'm probably not understanding (?<=pattern) correctlys{ (?<= \{name_a ) (?: (?: (?<= \s ) | (?<= param_[xy]=" ) (?: (?<= [^"] ) )+ (?<= " ) ) | param_[^xy]\w*="[^"]+" )+ (?<= \} ) }< eaten >gx;
The following works
s/ \{name_a ( (?: [^=\s]+ = "[^"]*" | \s+ )+ ) \}/ FunAt($1) /gex; sub FunAt { join '', '{name_a ', AtAt(@_) ,'}'; } sub AtAt { my %fun = $_[0] =~ m/([^=\s]+) = ("[^"]*")/gx; return join ' ', map { "$_=$fun{$_}" } grep /param_[xy]/, keys %fu +n; }
|
---|
Replies are listed 'Best First'. | |
---|---|
A reply falls below the community's threshold of quality. You may see it by logging in. |
In Section
Seekers of Perl Wisdom