Because \r\n are "special" chars in a regex I have a problem identifying what I actually need to put in my expression.
basically i have a string that looks something like ...
bla\r\nbla\r\nbla
.. and i'm looking to change it to ...
bla
bla
bla
... using a regular expression.
Any ideas?
\
is an escape character in regex and can be used to escape itself, meaning that you can write \\n
to match the text \n
.
Use the pattern \\r\\n
and replace with \r\n
.
You don't necessarily need regex for this (unless this is not the only thing you are replacing), but \r\n is the way to go in most variants of regex.
Examples:
PHP
$str = preg_replace("/\\r\\n/", "\r\n", $str);
or$str = str_replace('\r\n', "\r\n", $str);
(or "\\r\\n"
for the first argument)Ruby
str = str.gsub(/\\r\\n/, "\r\n")
orstr = str.gsub('\r\n', "\r\n")
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