RegExp.prototype.source
The text of the regular expression pattern, without delimiters or flags.
Syntax
regexp.source
Returns
string — The pattern source string.
Examples
const re = /ab+c/gi;
console.log(re.source);
Output
ab+c
const re = new RegExp("\\d+");
console.log(re.source);
Output
\d+
console.log(new RegExp("").source);
Output
(?:)
Notes
- A read-only accessor; it excludes the slashes and flags.
- An empty pattern reports as `(?:)` so it remains a valid literal.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |