Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by jethro (Monsignor)
on Feb 08, 2009 at 14:34 UTC ( #742259=note: print w/ replies, xml ) Need Help??


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

Without any modifiers $ matches the end of the string. But for practical reasons it sort of ignores a newline there. The practical reason is that you often read in lines from files and want to match without first having to chomp the line. A convenience for very small scripts and one liners. Here is a relevant citation from the perlre man page:

By default, the "^" character is guaranteed to match only the beginning of the string, the "$" character only the end (or before the newline at the end), and Perl does certain optimizations with the assumption that the string contains only one line. Embedded newlines will not be matched by "^" or "$". You may, however, wish to treat a string as a multi-line buffer, such that the "^" will match after any newline within the string (except if the newline is the last character in the string), and "$" will match before any newline. At the cost of a little more overhead, you can do this by using the /m modifier on the pattern match operator. (Older programs did this by setting $*, but this practice has been removed in perl 5.9.)


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-10-25 19:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (148 votes), past polls