Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: Question on Regex grouping

by ajguitarmaniac (Sexton)
on Dec 21, 2010 at 07:05 UTC ( #878166=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Question on Regex grouping
in thread Question on Regex grouping

Great! Just what I was looking for! Can I use the below mentioned approach to arrive at the same result?

if ($arr =~ /(\w*)(abc)(\d{5})/){ $a = $3 if (($arr =~ / (\w*)(def)(\d{8})/){ $b = $3 } } print $a; prnit $b;


Comment on Re^4: Question on Regex grouping
Download Code
Re^5: Question on Regex grouping
by Anonyrnous Monk (Hermit) on Dec 21, 2010 at 07:12 UTC

    Yes.  But don't use $a and $b :)  — they're special global variables (for sort).

      Alright!! Thank you!! Let me see how sort works now :-)

Re^5: Question on Regex grouping
by AnomalousMonk (Abbot) on Dec 22, 2010 at 05:38 UTC

    Also remember that if either (or both) or the regexes fail to match, one or the other (or both) of  $a and  $b (or whatever you finally decide to call them) will be undefined.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-07-06 21:58 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 (83 votes), past polls