Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Tell or determine whichever Perl regex group fails

by Corion (Patriarch)
on Jan 04, 2022 at 09:22 UTC ( [id://11140129]=note: print w/replies, xml ) Need Help??


in reply to Tell or determine whichever Perl regex group fails

I wish for that for a long time, but while a regular expression can definitively match, I haven't found a way to programmatically determine where the match fails. This is because a regular expression will try all alternatives and only after all of them have failed the entire regular expression has failed.

I think you could be clever and for any regular expression with a fixed length of atoms anchored to the start, you can tell where it fails, but any unanchored regex will simply fail "at the end" as that is the last position where it checks.

I also use Regexp::Debugger to find where a regexp fails to match. It is unwieldly if you construct your target regexp from variables, but I usually extract the offending regular expression (as string) and the target string into a separate file to check where things go sideways.

  • Comment on Re: Tell or determine whichever Perl regex group fails

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found