Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://742259]
shmem serves tea along with the cookies. (☕) x @CBMonks
[shmem]: hmm.. which makes emerge the question: is there a way to attach a subroutine to a variable, which is run as soon as that variable changes?
[moritz]: through a tie?

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-04-24 12:15 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (439 votes). Check out past polls.