How to convert RegExp to string in Javascript
Convert to string
toLocaleString()
and toString()
return the literal representation of the regular expression.
Example
var pattern = new RegExp("\\[oo\\]at", "gi");
console.log(pattern.toString()); // /\[oo\]at/gi
console.log(pattern.toLocaleString()); // /\[oo\]at/gi
The valueOf()
method for a
regular expression returns the regular expression itself.
The code above generates the following result.