How do you use a regular expression in replace function?



regexp (pattern)
RegExp object or literal. The match or matches are replaced with newSubStr or the value returned by the specified function.
Instead of using the /g syntax, you can construct a new RegExp object: 

(/g uisng for global string change)

var re = "3001/A/18716520/000/00";
var re = new RegExp("/", "g");

var Response = re.replace(ch, '_');

Result:

3001_A_18716520_000_00

Post a Comment

0 Comments