December 2023
Intermediate to advanced
242 pages
5h 28m
English
The exec() method executes a search on a string. If it finds a match, it returns an array containing the search result. If not, it returns null. Here is an example:
| | const str = "About 100ft"; |
| | const re = /(\d+)ft/; |
| | |
| | console.log(re.exec(str)); |
| | // → ["100ft", "100", index: 6, input: "About 100ft", groups: undefined] |
The resulting array contains the matched string as the first item. If there are any capturing groups within the match, they are listed from index 1. The array also comes with three properties:
If you use a global flag, exec() will use the value of
Read now
Unlock full access