On 1/20/07, Michael Alipio <[EMAIL PROTECTED]> wrote:
Hi,

I'm a bit confused here:

I have a regexp:

    ($date) = $log =~ /date=(\S+?)[\s+|,]/;

so if I have:

"date=2007-01-12 blah blah"

or

"date=2007-01-12,blah,blah"

I was able to retrieve "2007-01-12"

However, just recently after reading my notes on perl, I read that I should use 
parenthesis on regexp alternatives.

so this:

[\s+|,]

should be written as

(\s+|)

But if I use that parenthesis my regexp:

    ($date) = $log =~ /date=(\S+?)[\s+|,]/;

As I remember my regexp notes, If I want to match something, I will have to put it inside parenthesis. And if 
I change those "[ ]" into "( )" I'm afraid that I might also match those \s+ or 
","


Can you shed some light on this?

Thanks.

There have been some regex solutions posted already, but in the
general case, you're right that normal parenthesis both group and
capture.  If you want non-capturing parentheses, you can use
(?:<Insert regex you want to group but not capture here>).

So... you could use
($date) = $log =~ /date=(\S+?)(?:\s+|,)/;

See perldoc perlre for details.

- Jen

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to