The RegExp constructor creates a regular expression object for matching text with a pattern.
new RegExp(pattern, flags?)
pattern
A string that specifies the pattern of the regular expression.
flags optional
A string that contains flags that specify how to construct the regular expression.
The following flags are supported:
g
Global search. The regular expression will match all occurrences of the pattern in the target string.
d
Generate indices for substring matches.
i
Ignore case.
m
Multi-line search (allows ^ and $ to match line terminators within the target string).
s
Single-line search. . matches any character, including line terminators.
u
Unicode; treat pattern as a sequence of Unicode code points.
y
“Sticky” search that matches starting at the current position in the target string.
A new RegExp object.
(new RegExp("\\d+", "g")).test("123")
true
/\d+/g.test("123")
true