For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2006 > Re: split and grouping in regexp









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: split and grouping in regexp
Randal L. Schwartz

2006-11-01, 6:57 pm

>>>>> "Daniel" == Daniel Kasak <dkasak@nusconsulting.com.au> writes:

Daniel> I'm trying to split a date where the values can be separated by a dash '-' or
Daniel> a slash '/', eg:
Daniel> 2006-10-31 or 2006/10/31

If it's easier to talk about what to keep instead of what to throw away,
don't use split -- use regex match:

my ($y, $m, $d) = $string =~ /(\d+)/g;

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com