Standard built-ins
RegExp()
Constructs a regular expression from source text or a regex. Invalid patterns or flags throw SyntaxError; string patterns require string-level escaping.
Formal Syntax & Structure
javascript syntaxjavascript
new RegExp([pattern], [flags])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| pattern | String | RegExp | Pattern or existing regex. |
| flags | String | Flags; omitted may inherit from regex input. |
Return Value
RegExp
Regular expression instance.
Working Example
Example Snippetjavascript
console.log(new RegExp("\\d+").test("42"));