Javascript - RegExp toLocaleString(), toString() and valueOf()


toLocaleString() and toString() each return the literal representation of the regular expression.

Consider this example:

var pattern = new RegExp("\\[bc\\]at", "gi");
console.log(pattern.toString());          // /\[bc\]at/gi
console.log(pattern.toLocaleString());    // /\[bc\]at/gi

The toLocaleString() and toString() methods return the pattern as if it were specified in literal format.

The valueOf() method for a regular expression returns the regular expression itself.