At 7:39 AM -0700 5/25/11, Irfan Sayed wrote:
hi,

i have string like this
"2011/05/25 07:24:58 -0700 PDT" i need to match "2011/05/25" i wrote reg ex like this: ^\d\d\d\d//\d\d/\d\d$ but it is not working code is like this

$lin = "2011/05/25 07:24:58 -0700 PDT";
$lin =~ m/^\d\d\d\d//\d\d/\d\d$/;

You have two forward slashes there instead of one between the year and month fields. You will have to escape the forward slash with a backward slash if you use forward slash to delimit your regular expression.

If you use a different delimiter, you don't have to escape the slashes. Using extended regular expressions helps readability as well:

$lin =~ m{ \A (\d{4} / \d{2} / \d{2}) }x;

--
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to