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 »
Description
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 | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
RegExpObject.toString()
Parameters
None. |
Return Value
Type | Description |
---|---|
String | The string value of the regular expression |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.