JavaScript RegExp toString()
Example 1
Return the string value of the regular expression:
let pattern = new RegExp("Hello World", "g");
let text = pattern.toString();
Try it Yourself »
Definition and Usage
The toString() method returns the string value of the regular expression.
Example 2
Return the string value of the regular expression:
let pattern = /Hello World/g;
let text = pattern.toString();
Try it Yourself »
Browser Support
toString()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
RegExpObject.toString()
Parameters
None. |
Return Value
Type | Description |
---|---|
String | The string value of the regular expression |