Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How to enforce match priority irrespective of string position

by Polyglot (Friar)
on Mar 08, 2021 at 01:33 UTC ( #11129305=note: print w/replies, xml ) Need Help??


in reply to Re: How to enforce match priority irrespective of string position
in thread How to enforce match priority irrespective of string position

And that method worked! (Though I've had to restructure a bit to accommodate, as that was not in a simple substitution form.) I don't mind doing whatever is necessary to get things working, though...so thank you very much! I'll certainly upvote this when I get my next day's rations.

This part seems to be the crucial bit: (?=Point|\z) (?!\1). I find this sort of syntax confusing because it always seems to me that the "Point" here should have precedence over anything coming afterward in the regex sequence, in this case the "\1" backreference. If "Point" is already detected from the forward assertion, why can it be matched again (overlapped) by this reference, even if in the negative?

Well, no complaints at the moment, certainly, as at least the script is now past this hurdle. Thank you.

Blessings,

~Polyglot~

  • Comment on Re^2: How to enforce match priority irrespective of string position

Replies are listed 'Best First'.
Re^3: How to enforce match priority irrespective of string position
by tybalt89 (Prior) on Mar 08, 2021 at 02:25 UTC

    Because (?= and (?! are ZERO-WIDTH assertions.

      I appreciate knowing that, but while the assertion may be "zero-width," my mind still stumbles on the point that "Point" is certainly not zero-width. I'd always understood the "zero-width" aspect to be more related to the capturing and positioning of the match within the string. Are all look-arounds zero-width? If so, why must a look-behind be always of a specified length (width) that is not variable?

      Well, it may be that it's just too abstract for me.

      Thank you for your explanation.

      Blessings,

      ~Polyglot~

        This reference explains it quite well:

        lookaround actually matches characters, but then gives up the match, returning only the result: match or no match. That is why they are called “assertions”. They do not consume characters in the string, but only assert whether a match is possible or not.

        ... most regex flavors do not allow you to use just any regex inside a lookbehind, because they cannot apply a regular expression backwards. The regular expression engine needs to be able to figure out how many characters to step back before checking the lookbehind.

        Hope that helps.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-09-24 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?