Re: split and grouping in regexp
- From: arnaldo@xxxxxxxxxxx (Arnaldo Guzman)
- Date: Tue, 31 Oct 2006 01:10:32 -0500
On Tue, 2006-10-31 at 12:22 +1100, Daniel Kasak wrote:
I'm trying to split a date where the values can be separated by a dash
'-' or a slash '/', eg:
2006-10-31 or 2006/10/31
I'm using:
my ( $yyyy, $mm, $dd ) = split /(-|\/)/, $yyyymmdd;
but it doesn't work.
If I just do:
my ( $yyyy, $mm, $dd ) = split /-/, $yyyymmdd;
it works for dates separated by dashes, and if I do:
my ( $yyyy, $mm, $dd ) = split /\//, $yyyymmdd;
it works for dates separted by slashes.
Why can't I do both at the same time?
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@xxxxxxxxxxxxxxxxxxxx
website: http://www.nusconsulting.com.au
You should remove the parenthesis there:
my $date = "2006-10-06";
my ($year, $month, $day) = split m{-|/}, $date;
Now you should have what you need. Using group parenthesis actually
assigns the first "match" to the $month variable, which would either be
a "-" or a "/".
.
- References:
- split and grouping in regexp
- From: Daniel Kasak
- split and grouping in regexp
- Prev by Date: Re: POE performance issue.
- Next by Date: Re: [SPAM DETECT] split and grouping in regexp
- Previous by thread: Re: split and grouping in regexp
- Next by thread: Re: split and grouping in regexp
- Index(es):