Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Regex's, parentheses, and the mysterious ( ??{ } ) operator

by Clovis_Sangrail (Beadle)
on Jul 11, 2013 at 21:13 UTC ( #1043821=note: print w/ replies, xml ) Need Help??


in reply to Regex's, parentheses, and the mysterious ( ??{ } ) operator

Fortunately it looks like this regex still sets $`, $&, and $' properly, so as a practical matter I can use successive $' to search for several parenthesized strings.

$ cat p5.pl #!/opt/perl5.16/bin/perl use strict; use warnings; our $paren = qr/ # Need declared variable with use stri +ct. \( ( [^()]+ # Not parens | (??{ our $paren }) # Another balanced group (not interpol +ated yet) )* \) /x; # 'x' means ignore whitespace, comment +s. my $stuff = "On the outside now then (we go( in( and in (&stop)(awhile +) ( further ))) but still (here) ) and now (for a while) we are out a +gain."; $stuff =~ /($paren)/; print "Orig----------\n"; print "|" . $stuff . "|\n"; print '$1------------' . "\n"; print "|" . $1 . "|\n"; print 'Match---------' . "\n"; print "|" . $& . "|\n"; print 'B4------------' . "\n"; print "|" . $` . "|\n"; print 'After---------' . "\n"; print "|" . $' . "|\n"; print "----------\n"; $ ./p5.pl Orig---------- |On the outside now then (we go( in( and in (&stop)(awhile) ( further +))) but still (here) ) and now (for a while) we are out again.| $1------------ |(we go( in( and in (&stop)(awhile) ( further ))) but still (here) )| Match--------- |(we go( in( and in (&stop)(awhile) ( further ))) but still (here) )| B4------------ |On the outside now then | After--------- | and now (for a while) we are out again.| ---------- $


Comment on Re: Regex's, parentheses, and the mysterious ( ??{ } ) operator
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-12-28 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls