I have some text data that is printing out the actual characters "\r\n" (so four characters total). I'd like to replace those four characters with the single "\n" character, but I can't seem to make Python do it for me. I'm currently trying:
mytext.replace("\r\n", "\n")
But that just prints out "\n" (two characters, not one). I feel like I'm probably missing something obvious, but any help would be appreciated.
If your items are separated by pipes only, type the pipe character (“|”). Next, locate the “Search Mode” box and select “Extended.” This allows the replace action to convert “\n” into a newline character. Then, click “Replace All” on the right side of the window.
Create a string containing line breaks Inserting a newline code \n , \r\n into a string will result in a line break at that location. On Unix, including Mac, \n (LF) is often used, and on Windows, \r\n (CR + LF) is often used as a newline code.
In Notepad++ press Ctr+H to open the “Find and Replace” window. Under Search Mode: choose “Regular expression” and then check the “matches newline” checkbox.
I would recommend using splitlines instead of a regex or search/replace
"\n".join(mytext.splitlines())
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