Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Where can I find more examples of use of Special Backtracking Control Verbs?

by Eily (Monsignor)
on Nov 06, 2018 at 17:14 UTC ( #1225312=note: print w/replies, xml ) Need Help??


in reply to Where can I find more examples of use of Special Backtracking Control Verbs?

I'd suggest Super Search. Which will basically show that AnomalousMonk is the local expert on the subject :P. After a quick browse, I have extracted two bits of interresting (to me) information. First (*SKIP) and (*FAIL) can be used for something that quacks like variable length look behind assertions, as discussed here. Second, (*FAIL) is identical to (?!), and one is actually compiled to the other.

I find this interesting because I have actually never used any of the control verbs - I remember having a vague understanding of what they do, and how to use them, but not why I would need them - while I have used look-around assertions (mostly look ahead) on several occasions and have a more intuitive understanding of them.

On the "variable length look behind assertion" case though, a far simpler solution has been made available with \K. This may be one reason why (*SKIP) and (*FAIL) aren't very common, but might also be another gateway to understanding what they do

  • Comment on Re: Where can I find more examples of use of Special Backtracking Control Verbs?

Replies are listed 'Best First'.
Re^2: Where can I find more examples of use of Special Backtracking Control Verbs?
by AnomalousMonk (Bishop) on Nov 06, 2018 at 18:49 UTC

    \K is the basis for a variable length positive look behind assertion. The case discussed here implements a variable length negative look behind assertion, which in Perl must always be emulated in some way (ATM).


    Give a man a fish:  <%-{-{-{-<

      Ahem, yes. I failed to see that. Thanks pointing that out.

      On a completly far-fetched note, now that I think I understand the (*SKIP)(*FAIL) pattern, it seems to me that it only covers the subset of negative look behind assertions that do not come after any character has been matched. For example: /^(.{5})+(?<!ab*c)d/ (which is the same as matching /d(?!cb*a)(.{5})+$/ on the reverse string) can't be rewritten using the (*SKIP)(*FAIL) pattern (AFAICT). I'm sure this is a problem people stumble upon all the time :P

        For example: /^(.{5})+(?<!ab*c)d/ ... can't be rewritten using the (*SKIP)(*FAIL) pattern ...

        I don't see how it could be done, but I'm still looking. Certainly the trick has its limits. Still, it's handy in a few situations. However, variable width negative look-behind is, perhaps fortunately, not something one tends to really need very often. :)


        Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2019-10-18 02:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?