How to escape characters in javascript with a space before
11,990
You just need:
string.replace(/ \//g,"\n");
so that you're matching a space followed by an (escaped) forward slash.
This has some good examples: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
Author by
István Pálinkás
( [] < {} ) // true ( + "." != + "." ) // true
Updated on June 29, 2022Comments
-
István Pálinkás almost 2 years
I would like to escape a " /" (a slash with a space before) in a javascript expression.
Naturally, it works with this expression:
string.replace(/\//g,"\n");
It replaces all the "/"-s in my string with a "\n" (console linebreak).
But what I really need is an expression, or a method to replace " /"-s instead of "/"-s.
As You may know, unfortunatelly the escaping expression breaks this way:
string.replace(/\ //g,"\n");
Thanks for Your help!