Javascript replace regexp \\n with \n, \\t with \t, \\r with \r and so on
NickName:Joshua Beckers Ask DateTime:2020-02-09T12:10:59

Javascript replace regexp \\n with \n, \\t with \t, \\r with \r and so on

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

More about “Javascript replace regexp \\n with \n, \\t with \t, \\r with \r and so on” related questions

Javascript replace regexp \\n with \n, \\t with \t, \\r with \r and so on

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 ins...

Show Detail

Oracle Regexp to replace \n,\r and \t with space

I am trying to select a column from a table that contains newline (NL) characters (and possibly others \n, \r, \t). I would like to use the REGEXP to select the data and replace (only these three)

Show Detail

Javascript regexp replace capturing

I'm trying to use regex in a Nodejs app. I usually use it in Python and it seems to have some differences. Here is the problem : I have this string \newcommand{\hello}{@replace} and I want to re...

Show Detail

javascript string replace with RegExp

I got a problem with javascript RegExp. I want to replace the a.href with textbox value when I click on the button.But, I don't want to replace the whole string just want to find and replace those ...

Show Detail

Javascript - Having trouble using RegExp for a replace

I'm trying to do a Javascript replace (to remove some words from a string) but I require a variable to be used so I'm using new RegExp() as seen below however I can't figure out why the regular

Show Detail

Replace all CRLF with \r\n using REXEXP_REPLACE

I have a process that needs to strip all CRLF from SQL statements and store them with literal characters \r\n and stores this in a .json file. Later, this process is reversed when the .json file is

Show Detail

javascript: find/replace regexp help - bold, italic and specific characters

the HTML/concept: <textarea id="input"></textarea> <button onclick="format()">submit</button> <textarea id="output">&a

Show Detail

replace() not functioning as expected attempting to replace newline characters (/n /rn /r) in JavaScript

I have just started using JavaScript so this could just be a syntax error that I am overlooking or could be a regex error but the source of the code seemed to be well accepted. I got my code from ...

Show Detail

JavaScript RegExp objects

I try to write a simple Markdown parser in JavaScript. Therefore I want to check for the [link content][link id] syntax. I use the following code: data = data.replace( /\[(.*?)\][ ]*\[([0-9]+)\]/g...

Show Detail

javascript, replace \n with \r\n

I need to replace all \n with \r\n, but only if \n hasn't already \r previosly. i.e. Hello\nGreat\nWorld -> Hello\r\nGreat\r\nWorld Hello\r\nGreat\r\nWorld -> Hello\r\nGreat\r\nWorld. In Java i ...

Show Detail