Summary
The toString() method returns a string representing the regular expression.
Syntax
regexObj.toString()
Parameters
None.
Description
The RegExp object overrides the toString method of the Object object; it does not inherit Object.prototype.toString(). For RegExp objects, the toString method returns a string representation of the regular expression.
Examples
Example: Using toString
The following example displays the string value of a RegExp object:
myExp = new RegExp("a+b+c");
alert(myExp.toString()); // displays "/a+b+c/"
foo = new RegExp("bar", "g");
alert(foo.toString()); // displays "/bar/g"
Specifications
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 3rd Edition. Implemented in JavaScript 1.1 | Standard | Initial definition. |
| ECMAScript Language Specification 5.1th Edition (ECMA-262) | Standard | |
| ECMAScript Language Specification 6th Edition (ECMA-262) | Draft |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |