Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by LanX (Saint)
on Mar 07, 2021 at 13:43 UTC ( [id://11129267]=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

> (?= .*? $regex_1 ) .*? $regex_1

does it make sense to repeat the regex?

isn't it rather

(?= $re_cond_1 ) $re_match_1

?

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

Replies are listed 'Best First'.
Re^3: How to enforce match priority irrespective of string position
by rsFalse (Chaplain) on Mar 07, 2021 at 13:58 UTC
    Of course, '$re_cond_1' may be not equal to '$re_match_1'. But I wanted to show the simplest example. Further '\1' can be used to avoid self-repeating.
      > Of course, $re_cond_1 may be not equal to $re_match_1

      my point is, that it has IMHO no effect at all if it's identical.

      > But I wanted to show the simplest example

      too simple examples can confuse :)

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

        too simple examples can confuse :)

        Ha! Well, I'm easy to confuse. I'm not a "real" programmer--well, I've done some amazing things, but most here would be surprised at how I'd done them. I have a considerable handicap: it seems the part of my brain that should process abstract math and logic went undeveloped. I've never been able to grasp abstractions, even in the world of programming. Everything has to be concrete for me--i.e., no objects, no references, no "bless-ings"...I just don't "get" any of this stuff, and what I don't understand I cannot implement. This means I have also found very few modules written by others that I am able to use--especially ones like parsers. In all probability, there's a module out there somewhere that would help do what I need to do; but I would probably try studying it for days to figure out how to implement it, and even then may not succeed. Been there, done that. So, I just have to do my own thing. Every time.

        Note that I am paid nothing for my programming--it's all volunteer to help others, and I'm internally driven to get it done, knowing no one else filling this niche.

        Blessings,

        ~Polyglot~

        > my point is, that it has IMHO no effect at all if it's identical.

        I think you're right! And my suggestion simply reduces to the same but without look-ahead :).
        Too simple example even confused its author.
Re^3: How to enforce match priority irrespective of string position
by Polyglot (Chaplain) on Mar 07, 2021 at 14:02 UTC

    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~

      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).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found