Re: Simple compiled regexp not working
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Wed, 30 Aug 2006 20:49:32 -0400
"u" == usenet <usenet@xxxxxxxxxxxxxxx> writes:
u> Kindly consider the following code which illustrates my question:
u> #!/usr/bin/perl
u> use strict; use warnings;
u> my $line = '08/29/2006 to 08/30/2006';
u> my $date_rx = qr{m!\d{2}/\d{2}/\d{4}!};
ok, this will make you smack your head in a big D'Oh!
why do you think the m!! INSIDE the qr{} means anything special? the m//
is an op and pair of delimiters and not a regex itself. so since m and /
are not metachars (the / is not a { or }) then they are compiled to
themselves as plain chars to match. and they don't match.
u> print "regexp matches\n" if $line =~ m!\d{2}/\d{2}/\d{4}!;
u> print "date_rx matches\n" if $line =~ /$date_rx/;
u> __END__
u> The way I read perlop, both print statements should fire, as they
u> should be doing the exact same match. But I only see the first one.
u> grrr. This ought to be really simple.
it is simple. you missed the part about the regex itself vs the op and
delimiters.
i will now let you smack yourself silly. no charge.
:)
uri
--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.
- Follow-Ups:
- Re: Simple compiled regexp not working
- From: usenet
- Re: Simple compiled regexp not working
- References:
- Simple compiled regexp not working
- From: usenet
- Simple compiled regexp not working
- Prev by Date: Simple compiled regexp not working
- Next by Date: Re: Simple compiled regexp not working
- Previous by thread: Simple compiled regexp not working
- Next by thread: Re: Simple compiled regexp not working
- Index(es):
Relevant Pages
|