Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: regex needed

by aaron_baugher (Curate)
on Jul 12, 2012 at 13:27 UTC ( #981399=note: print w/replies, xml ) Need Help??

in reply to Re^2: regex needed
in thread regex needed

It may help to talk it through in words first. The pattern you're looking at is:

  • Two dollar signs (metacharacters, will need escaping)
  • An open parenthesis (also needs escaping)
  • Some text up to a closed parenthesis (capture this in $1)
  • A closed parenthesis (escaped)
  • Anything else that exists beyond that (captured in $2)

Now just put those elements together in a regex:

if( $line =~ m[ \$\$ # two dollar signs \( # open paren ([^)]+) # capture until closed paren \) # close paren (.*) # capture the rest, if any ]x ){ # do stuff with $1 and $2 }

Aaron B.
Available for small or large Perl jobs; see my home node.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981399]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2018-06-20 07:55 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.