Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by Polyglot (Chaplain)
on Mar 07, 2021 at 14:02 UTC ( [id://11129272]=note: print w/replies, xml ) Need Help??


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

I must say that this syntax confuses me. I am already using a lookahead to define the forward edge of the match (versus where the next match will start in the global substitution), and everything up to but not including that lookahead needs to be captured. I've never thought one could capture from a lookahead...but perhaps I'd misunderstood. I'm also using backslash lookaround assertions, because some of what is matched will be matched again (these are the false positives) and for an unpredictable number of times (fewer than 20).

I tried putting rsFalse's suggestion to use but was unable to get the match to succeed. I don't think I understand it well enough.

Blessings,

~Polyglot~

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

Replies are listed 'Best First'.
Re^4: How to enforce match priority irrespective of string position
by LanX (Saint) on Mar 07, 2021 at 14:43 UTC
    you can separate the "condition to match" (in the lookahead) from the actual match-pattern.

    Point is that a failed partial match might move the pos forward, but if the condition fails pos won't be changed before trying the next or-alternative.

    rsfalse might provide/link an example.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      I guess OP might try use his '(.*?)' within every branch to achieve priority matches. But as he wants to capture it, he will use more capturing groups, e.g. 1+2, 3+4 and 4+5, where $1, $3 and $5 is what '(.*?)' capture. Or he may use '(?|...)' group for parallel numbering (https://perldoc.perl.org/perlre#(?%7Cpattern).
        Frankly, I don't know what OP really wants. at least I think so ... :)

        As is said he should provide test cases. (If he can't, this would mean that he doesn't know it either. ;)

        And we are at risk to get lost in speculations.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        I have only a few "branches" (alternations) for the forward-looking assertion. But how would I put a capture group there? In any case, I've made several attempts at this now with no success. For some reason the match always ends at the earliest possible alternation, apparently recognizing the (.*?) in the separate branches as being equal. Going to an unqualified greedy capture would not work either, as that would potentially slurp entire paragraphs instead of sentences until a match would be found--combining chunks that should remain separate.

        For my part, any way that will do the job works for me. I don't mind, for a one-time-use script like this, writing pages of messy looking code that is inefficient, ugly, whatever--if so long as it would get the job done! So having a large number of capture variables is a non-issue. I've sometimes gone above 30 on those for a job of this nature! But in this particular case, that is not going to solve the problem.

        Blessings,

        ~Polyglot~

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found