December 2023
Intermediate to advanced
242 pages
5h 28m
English
| Recipe 23 | Creating Your First Regular Expression |
Before using the recipes in Parts 2 and 3, you need to know how to implement regular expressions in your code. In JavaScript, you have two options for creating regular expressions: you can either use the RegExp() constructor or use the regex literal. When using the literal form, you’ll need to enclose the pattern in a pair of forward slash (/) characters, like this:
| | const re = /Hello/; |
This regex pattern is made up of five characters that tell the regex engine to find a direct match for “Hello” in a string. A pattern can be as simple as a single literal character such as “i.” If there are multiple occurrences of “i” in a string, it matches the first one. ...
Read now
Unlock full access