Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Recursive Regular Expression Help

by me (Initiate)
on Apr 12, 2008 at 03:06 UTC ( [id://679932]=note: print w/replies, xml ) Need Help??


in reply to Re: Recursive Regular Expression Help
in thread Recursive Regular Expression Help

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: Recursive Regular Expression Help

Replies are listed 'Best First'.
Re^3: Recursive Regular Expression Help
by GrandFather (Saint) on Apr 12, 2008 at 04:33 UTC

    In that case the answer is easy - switch to using Perl then you take advantage of the resources provided by PerlMonks.


    Perl is environmentally friendly - it saves trees
Re^3: Recursive Regular Expression Help
by nobull (Friar) on Apr 12, 2008 at 14:03 UTC
    So you had some working code, you made a change, and problems ensued?

    Perhaps if you showed us the change you made we could see what you did wrong. At a random shout in the dark you inserted stuff inside the recursive part of the pattern. PCRE now supports the reusable sub-expression syntax.

    The problem of matched parentheses is the most commonly quoted example of using this construct.

    my $bal = qr/ (?<bal> # Name the rule (optional) \{ # Open brace (?> # Possessive subgroup (?> [^{}]+ ) # Grab all the non braces | # or (?&bal) # Recurse )* # Zero or more times \} # Close brace ) # End named rule /x; if ('{x{x}y{x}x}' =~ /^$bal$/ ){ print "It's balanced\n"; } $_= 'XXXX function xxx() {x{x}y{x}x} XXXX'; while ( /\bfunction\s+(\w+)\(\)\s*($bal)/g ){ print "function: $1\nbody: $2\n"; }

    This, of course, is Perl code - adapting it to PHP is left as a exercise for the reader.

    I should add, this only checks for nested {} it doesn't know to ignore {} within quotes - that too is possible by hybridising the above with the tricks for parsing CSV.

Log In?
Username:
Password:

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

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

    No recent polls found