Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: When exactly do Perl regex's require a full match on a string?

by AnomalousMonk (Archbishop)
on Feb 09, 2009 at 05:53 UTC ( [id://742357]=note: print w/replies, xml ) Need Help??


in reply to Re: When exactly do Perl regex's require a full match on a string?
in thread When exactly do Perl regex's require a full match on a string?

[...] Perl accepts  m'^a$q' which can never match... unless  /m is somehow implied [...]
With or without the /m modifier, it can never match against any string whatsoever because as the regex is defined,  $ is required to match before something other than an end-of-string or newline:  'q' follows it in the regex.

If the regex is defined with a newline to follow the  $ metacharacter, if the  /m modifier is used and if the interpolation-suppressing  ' (single-quote) character is used as the regex delimiter, then a match is possible against a string with an embedded newline:

>perl -wMstrict -le "my $s = qq{a\nq}; print $s =~ m'^a$q' ? ' ' : 'NO ', 'match'; print $s =~ m'^a$q'm ? ' ' : 'NO ', 'match'; print $s =~ m'^a$\nq' ? ' ' : 'NO ', 'match'; print $s =~ m/^a$\nq/m ? ' ' : 'NO ', 'match'; print $s =~ m'^a$\nq'm ? ' ' : 'NO ', 'match'; " NO match NO match NO match NO match match

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://742357]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-18 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found