> -----Original Message-----
> From: Nikola Janceski [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 31, 2002 11:27 AM
> To: Beginners (E-mail)
> Subject: regex capturing
> 
> 
> $\ = "\n";
> $date = "20020731";
> print join "/", ($date =~ /(\d{4})(\d{2})(\d{2})/)[1,2,0]; # 
> this works
> print join "/", ($date =~ /(\d{4})(\d{2}){2}/)[1,2,0]; # this doesn't
> 
> __END__
> 
> why did the second pattern not capture the second occurance of \d{2} ?

But it does capture the second occurrence (the 31). It doesn't capture
the first (the 07).

In the absence of /g, it would seem that since there are only two
sets of parens in the second regex, only two values can be captured.
The {2} quanitifier would simply cause $2 to be "reused".

> Is this the correct action? or should it capture the second one in the
> second example?
> Is there a way to capture like so (like second example as I 
> expected it to
> work)?

I would think /g would have to be used somehow, but I do not know
how.

Of course, the simple:

   /(\d{2})/g

works, returning '20', '02', '07', '31'.

But that's not what you're after.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to