I'm having an HTML Input field where the user can enter a delimiter.
This delimiter can include \n, \t, \r
and so on. When I append the delimiter to a string in javascript it is appended as \n instead of as a newline character.
While I can use str.replace(/\\n/g, "\n")
and so on to replace one variation it does not work if I write a general catch-all regexp like str.replace(/\\([a-z])/g, "\$1")
since this just replaces \n with \n again.
How do I have to rewrite the RegExp to replace all double backslashes in front of a character?
Copyright Notice:Content Author:「Joshua Beckers」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60133377/javascript-replace-regexp-n-with-n-t-with-t-r-with-r-and-so-on