Regular Expression
suggest changeSyntax
let regex = /pattern/flagslet regex = new RegExp("pattern", flags)let isMatch = regex.test("text")let results = regex.exec("text")
Parameters
| Flags | Details |
|---|---|
| g | global. All matches (don’t return on the first match). |
| m | multi-line. Causes ^ & $ to match the begin/end of each line (not only begin/end of string). |
| i | Case-insensitive matching. With u or v, case folding is Unicode-aware. |
| u | Unicode mode. The pattern is interpreted as code points, not lone UTF-16 code units. It cannot be combined with v. |
| y | Sticky: match only at lastIndex, not at a later index. |
d, s, and v are described on the flags page linked below. Without u or v, a pattern uses UTF-16 code units.
The RegExp object is only as useful as your knowledge of Regular Expressions is strong. See here for an introductory primer, or see MDN for a more in-depth explanation.
Check if string contains pattern using .test
Replacing string match with a callback function
Using Regex.exec with parentheses regex to extract matches of a string
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents