in reply to Regex Pop Quiz with .*, /g, and /s
I'm not really into the quiz thing (except maybe in the polling section), so I just ran it.
The answer is "none of the above". Since you haven't used the /m modifier, Perl won't treat it as a "single line". The replacement first takes off the first three characters (which includes the newline), and then it goes for another pass to get the last two characters.
I'm not really all that up on how /m does what it does, but the $* perlvar entry talks about optimization. I take this to mean that it tells Perl when to get sloppy in the name of speed.
What I find most interesting, however is that the /g seems to have something to do with it too. That is /ms does one replacement, but /gms does two replacements.
It makes my brain hurt. Basically, when you replace something that can have zero width, you're headed for a land of confusion (stop by and say hi; I hang out there a lot).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex Pop Quiz with .*, /g, and /s
by ikegami (Patriarch) on Oct 02, 2007 at 18:22 UTC |