in reply to Re^6: How do I display only matches
in thread (SOLVED) How do I display only matches
If I write a "\n" on my Windows machine, that means 2 characters: <CR><LF> (Carriage Return, Line Feed). So when you write "foo\r\n", on Windows that means <CR><CR><LF>. This extra <CR> means that the line doesn't end in "\n", <CR><LF> (Carriage Return, Line Feed). There is indeed something else between the "o" and the line ending and your regex doesn't match
I've seen you say something along these lines a couple times before, and I'm sorry, but it's flat out wrong.
C:\>perl -wMstrict -MDevel::Peek -e "my$x=qq{\n};Dump($x)" SV = PV(0x32aa98) at 0x577ef8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x556ba4 "\n"\0 CUR = 1 LEN = 10 COW_REFCNT = 1
Note CUR = 1 - there is only one character in that string, not two. I dimly remember that there might have been some builds of Perl for Windows back in the 90's that may have tried to handle it differently, and I remember being confused by this early on as well, but for a long time now, on both Windows and *NIX, \n is LF, and that's what Perl uses internally. The difference is that on Windows the :crlf layer translates that on input and output, but it doesn't change the internal representation, how regexes work, or the default $/ - even on Windows, it's "\n", one byte, "\x0A".
I suggest you take the time to read Newlines in perlport and PerlIO.
I copied the text for "$" verbatim from the Perl regex docs.
Where in the Perl docs does it say $ matches before \r?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: How do I display only matches
by Marshall (Canon) on Sep 25, 2019 at 21:58 UTC | |
by haukex (Archbishop) on Sep 25, 2019 at 22:08 UTC | |
by Marshall (Canon) on Sep 26, 2019 at 00:52 UTC | |
by haukex (Archbishop) on Sep 26, 2019 at 06:04 UTC | |
by Marshall (Canon) on Sep 27, 2019 at 23:17 UTC | |
|