Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: RegExp: pos management in global substitution

by OlegG (Monk)
on Sep 03, 2011 at 17:55 UTC ( #924012=note: print w/ replies, xml ) Need Help??


in reply to Re: RegExp: pos management in global substitution
in thread RegExp: pos management in global substitution

Interesting, but it depends of new line. In my example each tag separated by new line, but it is special case.
And it seems your regexp could be more efficient:

s( (?: (?: \G (?<! \A) | \A {name_a) $not_sp_param*+ \K) \s+ \w+ = \" [^^\"]* \" ) ()xmsg;


Comment on Re^2: RegExp: pos management in global substitution
Download Code
Re^3: RegExp: pos management in global substitution
by AnomalousMonk (Monsignor) on Sep 03, 2011 at 23:10 UTC
      Your variant still depends of new line. I mean it doesn't work properly with
      {name_b param_v="wh"}{name_a param_x="abc" param_a="fsd" param_y="def" +} {name_z param_sd="zka" param_s="df"}{name_a param_y="wtf" param_z="kro +" param_ch="www"}
      But thanks anyway. When I parsed your regexp I found new for me \K and totally understood how \G works. See below my solution based on your. Seems it works properly.
      s/ (?:\{name_a | \G) [^{}]+? \K \w++(?<!param_[xy]) ="[^"]+" //xg;

        I appreciate receiving the latest piece of your specification puzzle. I may not have a chance to do anything with it the rest of this weekend,
        but thanks anyway.

        The implied specification of Re^4: RegExp: pos management in global substitution can be met by changing the regex sub-expression (actually, it happens to be the whole regex)
            (?: \G (?<! ^) | ^ \{ name_a) $param_xy*+ \K $param_any
        to
            (?: \G (?<! \A) | \{ name_a) $param_xy*+ \K $param_any
        in the function  xform() of Re: RegExp: pos management in global substitution (see Update 2).

        OK, so what's the next specification increment? Totally arbitrary embedded whitespace, including newlines? Bring it on!

        BTW: The discussion of the "\G assertion" in the Regexp Quote Like Operators section of perlop includes the disquieting warning 'Note also that, currently, "\G" is only properly supported when anchored at the very beginning of the pattern.' (emphasis added). I don't understand all the implications of this restriction, but I strive diligently, perhaps slavishly and superstitiously, to heed it, even making sure that in a regex expression like
            \G (?<! \A)
        (end of last match except when at absolute start of string) the  \G assertion appears at the very start of the regex. I mention this because I noticed the expression
            (?:\{name_a | \G)
        in your code and I don't know its possible effect(s). You have been warned!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://924012]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-08-01 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls