in reply to understanding (*SKIP:...)
That (*SKIP:name) precedes (*MARK:name) in your pattern makes no sense, and leads me to think you believe a MARK is akin to a label and a SKIP is akin to a goto. That is not the case at all.
What we're marking and skipping to are positions in the string being matched.
(*MARK:name) bookmarks the current match position under the provided name.
(*SKIP:name) prevents everything before the named bookmarked position from being part of the final match if we backtracking through this.
(*SKIP) prevents everything before the position from being of the final match if we backtracking through this.
(*SKIP) is basically the same as (*MARK:anon)(*SKIP:anon).
Solution:
if ( "aab" =~ /(.)\1(*SKIP)(*FAIL)|.*/ ) { say $&; # b }
(*SKIP) was matched at position 2. When (*FAIL) caused the matching to backtrack through (*SKIP), everything before position 2 was eliminated from potential matches.
Non-trivial example using (*MARK:...):
If instead you want ab, you could use
if ( "aab" =~ /(.)(*MARK:go)\1(*SKIP:go)(*FAIL)|.*/ ) { say $&; # ab }
This time, only the text before position 1 was eliminated from potential matches.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: understanding (*SKIP:...)
by ysth (Canon) on Jun 12, 2025 at 02:06 UTC | |
|
Re^2: understanding (*SKIP:...)
by ysth (Canon) on Jun 11, 2025 at 23:09 UTC | |
by ikegami (Patriarch) on Jun 12, 2025 at 00:19 UTC |