Grokking Advanced JavaScript
Vote

0% completed

​

The RegExp Object

The two patterns below look the same, yet only one of them finds the digits in "42".

d+ \d+ false true

Both patterns are created with the RegExp constructor, which builds a regular expression from a string. Inside a JavaScript string, a backslash starts an escape sequence, and "\d" is simply the letter d. The first pattern therefore searches for one or more letters d. To put a real backslash into the pattern, the string must contain two backslashes, as in "\\d+".

Creating a pattern with the constructor

const regex = new RegExp(pattern, flags);

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content