We have this string (without new line at the end):
The quick brown fox jumps over the lazy dog
I want to match the entire string until new line \n or end $ occurs.
[\n$] - didnt work.(\n|$) - did workQuestion: Why doesnt [\n$] match the string while (\n|$) does?
Because $ in a character class is seen as a literal
Another way to look at it: a character class matches exactly one character. The end-of-line matched by $ is an empty string. That's why and end-of-line cannot be matched by a character class.
(As a consequence, the only possible interpretation for $ is the literal.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With