I have a regex expression which removes any backslashes from a string if not followed by one of these characters: \\ / or }.
It should turn this string:
<
The required regex is as simple as \\.
You need to know however, that the second argument to replace()
can be a function like so:
result = string.replace(/\\./g, function (ab) { // ab is the matched portion of the input string
var b = ab.charAt(1);
switch (b) { // if char after backslash
case '\\': case '}': case '/': // ..is one of these
return ab; // keep original string
default: // else
return b; // replace by second char
}
});