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

Re^2: Why \n matches but not $^? (weight)

by procura (Beadle)
on Oct 13, 2008 at 21:32 UTC ( #716864=note: print w/ replies, xml ) Need Help??


in reply to Re: Why \n matches but not $^? (weight)
in thread Why \n matches but not $^?

If 'm' as flag causes ^ and $ to gain magic as in

m Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string.

and $ matches end-of-line (or before newline) as in

           $   Match the end of the line (or before newline at the end)

It might be arguable that the newline would be matched by $ in

$ perl -Mre=debug -wle'"ABC\nDEF" =~ m/C(?:$)^D/m' Freeing REx: `","' Compiling REx `C(?:$)^D' size 7 Got 60 bytes for offset annotations. first at 1 rarest char D at 1 1: EXACT <C>(3) 3: MEOL(4) 4: MBOL(5) 5: EXACT <D>(7) 7: END(0) anchored "CD" at 0 (checking anchored) minlen 2 Offsets: [7] 1[1] 0[0] 5[1] 7[1] 8[1] 0[0] 9[0] Omitting $` $& $' support. EXECUTING... Guessing start of match, REx "C(?:$)^D" against "ABC DEF"... Did not find anchored substr "CD"... Match rejected by optimizer Freeing REx: `"C(?:$)^D"'

I understand that it doesn't. Making the newline explicit as in tye's example does

$ perl -Mre=debug -wle'"ABC\nDEF" =~ m/C(?:$)$\?^D/m' Freeing REx: `","' Omitting $` $& $' support. EXECUTING... Compiling REx `C(?:$) ?^D' size 11 Got 92 bytes for offset annotations. first at 1 rarest char D at 0 rarest char C at 0 1: EXACT <C>(3) 3: MEOL(4) 4: CURLY {0,1}(8) 6: EXACT <\n>(0) 8: MBOL(9) 9: EXACT <D>(11) 11: END(0) anchored "C"$ at 0 floating "D" at 1..2 (checking floating) minlen 2 Offsets: [11] 1[1] 0[0] 5[1] 8[1] 0[0] 7[1] 0[0] 9[1] 10[1] 0[0] 11[0] Guessing start of match, REx "C(?:$) ?^D" against "ABC DEF"... Found floating substr "D" at offset 4... Found anchored substr "C"$ at offset 2... Starting position does not contradict /^/m... Guessed: match at offset 2 Matching REx "C(?:$) ?^D" against "C DEF" Setting an EVAL scope, savestack=6 2 <AB> <C DEF> | 1: EXACT <C> 3 <ABC> < DEF> | 3: MEOL 3 <ABC> < DEF> | 4: CURLY {0,1} EXACT <\n> can match 1 times out of 1... Setting an EVAL scope, savestack=6 4 <ABC > <DEF> | 8: MBOL 4 <ABC > <DEF> | 9: EXACT <D> 5 <ABC D> <EF> | 11: END Match successful! Freeing REx: `"C(?:$)\n?^D"'


Comment on Re^2: Why \n matches but not $^? (weight)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-12-21 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls