prasad prasad - 1 year ago 66
HTML Question

Regex match with '\' slash and replace with '\\'?

I was converting normal string in to latex format.So i was created the latex code match and replace the

single slash into
double slash.why the i need it Refer this link.I tried Below code :

function test(){
var tex="$$\left[ x=\left({{11}\over{2}}+{{\sqrt{3271}}\over{2\,3^{{{3}\over{2} $$";
var tex_form = tex.replace("/[\\\/\\\\\.\\\\]/g", "\\");
document.getElementById('demo').innerHTML=tex_form;//nothing get

<p id="demo"></p>

Not getting any output data.But the match in this link

i wish to need replace the

Answer Source

why the i need it

As the question you link to says, the \ character has special meaning inside a JavaScript string literal. It represents an escape sequence.

Not getting any output data.But the match in this link

The escape sequence is processed when the string literal is parsed by the JavaScript compiler.

By the time you apply your regular expression to them, they have been consumed. The slash characters only exist in your source code, not in your data.

If you want to put a slash character in your string, then you need to write the escape sequence for it (the \\) in the source code. You can't add them back in with JavaScript afterwards.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download