"foo\r\nbar".replace(/(foo).+/m, "bar")
Hello. I can not understand why this code does not replace foo on bar
I can not understand why this code does not replace foo on bar
Because the dot .
explicitly does not match newline characters.
This would work:
"foo\r\nbar".replace(/foo[\s\S]+/m, "bar")
because newline characters count as whitespace (\s
).
Note that the parentheses around foo
are superfluous, grouping has no benefits here.
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