Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: newline behavior in Regular Expression

by halley (Prior)
on Apr 12, 2004 at 18:54 UTC ( #344474=note: print w/replies, xml ) Need Help??


in reply to newline behavior in Regular Expression

Congrats. I didn't even know that IE would honor <font size="+10"> but you proved it. I should print this question out as a poster for my bare wall here.

The $ means end-of-line, not end-of-string. The end of line is true just before any trailing newline character. So if $X had a newline before, it won't replace the newline after. One preventative measure would be to use chomp($X) beforehand.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Re: newline behavior in Regular Expression
by bart (Canon) on Apr 12, 2004 at 19:22 UTC
    The $ means end-of-line, not end-of-string
    Nope. That's only the case with the option /m enabled. Unless I misunderstand what you mean...? Which is not exactly very clear to me.

    I think the OP's problem is that he used /PAT(.*?)$/ and expected to match the final newline as well. As the /$/ does match just before the final newline as well as at the very end of the string, the non-greediness makes it pick the shortest match, thereby leaving the newline alone. Drop the '?' to make it work.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-10-26 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?