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

delayed interpolation of regexps & recursion

by Blop (Monk)
on Jul 27, 2001 at 17:33 UTC ( [id://100293]=perlquestion: print w/replies, xml ) Need Help??

Blop has asked for the wisdom of the Perl Monks concerning the following question:

I read in Tom Christiansen's (not so recent) Seven Stages of a Perl Programmer the following thing about regexps:
Simple regular expressions cannot match nested data because their primitives are: repetition, alternation, and sequence. There's no facility for recursion.

Perl 5.6 added delayed interpolation of regular expressions, and this gives the ability to be recursive and thus to match nested data.
So I tried to look for info about this "delayed interpolation", but could not find any. I'm frustrated because I'm feeling like I'm missing something. Would you have good resources or examples concerning this recursion ability, and how it helps with nested data? Is it as fun as it looks in Tom C's description?

Blop!
  • Comment on delayed interpolation of regexps & recursion

Replies are listed 'Best First'.
Re: delayed interpolation of regexps & recursion
by bikeNomad (Priest) on Jul 27, 2001 at 18:25 UTC
    I think what he's referring to is the (??{}) facility. From perlre:
    "(??{ code })" WARNING: This extended regular expression feature is considered highly experimental, and may be changed or deleted without notice. A simplified version of the syntax may be introduced for commonly used idioms. This is a "postponed" regular subexpression. The "code" is evaluated at run time, at the moment this subexpression may match. The result of evaluation is considered as a regular expression and matched as if it were inserted instead of this construct. The "code" is not interpolated. As before, the rules to determine where the "code" ends are currently somewhat convoluted. The following pattern matches a parenthesized group: $re = qr{ \( (?: (?> [^()]+ ) # Non-parens without backtracking | (??{ $re }) # Group with matching parens )* \) }x;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-25 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found