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

Re^2: regex needed

by doubledecker (Scribe)
on Jul 12, 2012 at 10:46 UTC ( #981362=note: print w/ replies, xml ) Need Help??


in reply to Re: regex needed
in thread regex needed

sorry, from $line, I need DATE in $1 and _RE_IRD_Soc in $2 $line2, $line3 doesn't have anything in $2. my idea is to have one regex which satisfy both conditions.


Comment on Re^2: regex needed
Re^3: regex needed
by cheekuperl (Monk) on Jul 12, 2012 at 11:29 UTC
    Check if this works:
    my $line = '%TMP%\$$(DATE)_RE_IRD_Soc'; my $line2 = '%RESULTS%\$$(DATE_USA)' ; my $line3 = '%RESULTS%\$$(1110_DATE_USA)'; @lines=($line,$line2,$line3); foreach $elem (@lines) { if($elem=~m/.*\$\$(\(.*\))(.*)?/) { print "\nFirst: $1, Second: $2"; } }
Re^3: regex needed
by aaron_baugher (Deacon) on Jul 12, 2012 at 13:27 UTC

    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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2014-11-22 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (125 votes), past polls