Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: When the only tool you have is a screwdriver...

by mr_ron (Chaplain)
on Oct 08, 2015 at 16:22 UTC ( [id://1144199]=note: print w/replies, xml ) Need Help??


in reply to Re: When the only tool you have is a screwdriver...
in thread When the only tool you have is a screwdriver...

I would just like to explain a bit about giving up on regex calisthenics. The problem is trying to match a "recursive pattern" another example of which would be matching balanced parenthesis which is a Perl FAQ.

p =~ () p =~ (p) p =~ pp

The faq and answer are here: Can I use Perl regular expressions to match balanced text?

Ron

Replies are listed 'Best First'.
Re^3: When the only tool you have is a screwdriver...
by sundialsvc4 (Abbot) on Oct 08, 2015 at 16:50 UTC

    Yes, but your situation is not necessarily “balanced.”   In the left/right parenthesis example, once the right-paren is seen, the matter is resolved.   But in some of your examples, we see multiple occurrences of "e".   Thus, in the general case, more-than-one recursion might have to be entered, and then backed-out in what turns out to be a failed parse-branch.   I do not believe that you can expect the regex engine to be that smart, although other Monks may promptly jump-in and show that I am wrong.

    However ... the saving grace might be “your actual data.”   If, for example, the terminal-tokens always consist of single characters, some sort of one- or one-and-three- character lookahead might be sufficient to resolve ambiguity.   After all, you do not always have to write for the general case:   you merely have to write what gets the job done in your case.   (Yay!)

    Even so, I think that this requirement (IMHO) has stepped beyond what you can reasonably expect from regular-expressions alone:   it is, I think, “a parsing problem.”   (By that I mean, “some sort of heuristic will be required, on top of what regexes alone can give you.)   With good fortune, you will find that there is an existing implementation of a heuristic (a parser) that will do the job.   Without good fortune, you will hack.   ;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found