Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: RE: Answer: What can regular expressions NOT do?

by Joey The Saint (Novice)
on Mar 20, 2001 at 20:48 UTC ( [id://65731]=note: print w/replies, xml ) Need Help??


in reply to RE: Answer: What can regular expressions NOT do?
in thread What can regular expressions NOT do?

Well, I actually asked for something similar ages ago on comp.lang.perl.moderated (I wanted to match balanced braces in C++ code) and was treated to the following solution which works quite handily on arbitrary-depth nesting for parens.

$string = "((()()())"; # one unbalanced paren ($re = "\Q$string") =~ s/\\(\()|\\(\))/$1\\$1$2$2/g; my @a = eval { $string =~ $re }; die "Mismatched brackets in '$string'\n" if $@;

-J.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found