JS | RegExp Partial Replace
by Zoltan Boros
HTML
<pre id="out">
</pre>
JavaScript
var outputElement = document.getElementById('out');
function print(text)
{
outputElement.innerHTML += text + "\n";
}
function insertSpaceAfterBackSlash(text)
{
return text.replace(/\\([^ ])/g, "\\ $1");
}
var text = "Foo\\ Bar\\Baz-Foo\\ Bar\\Baz";
print("Original text: '" + text + "'");
print("Modified text: '" + insertSpaceAfterBackSlash(text) + "'");