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

Re: Deriving Regular Expressions

by I0 (Priest)
on Apr 19, 2002 at 05:38 UTC ( #160439=note: print w/ replies, xml ) Need Help??


in reply to Deriving Regular Expressions

# my favorite cause for generating regexes from strings is to match balanced text:

$_ = "sin(atan2(sin(1),cos(1))),atan2(1,1),cos(atan2(sin(2),cos(2)))\n +"; (my $re=$_)=~s/((\()|(\))|.)/${[')','']}[!$3]\Q$1\E${['(','']}[!$2]/gs +; $re= join'|',map{quotemeta}eval{/$re/}; die $@ if $@ =~ /unmatched/; print while s/(\w+\(($re)\))/$1/ee;


Comment on Re: Deriving Regular Expressions
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2015-07-08 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls