| Symbol | Meaning |
|---|---|
(x) |
Capturing Parentheses: Matches x and remembers it. The capture allows us to reference it later. |
(?:x) |
Non-capturing Parentheses: Matches “x” but does not remember the match. |
x(?=y) |
Lookahead: Matches “x” only if it is followed by “y”. |
(x|y) |
Matches “x” or “y” |
| Symbol | Meaning |
|---|---|
* |
Matches the string 0+ times. Equivalent to {0,} |
+ |
Matches the string 1+ times. Equivalent to {1,} |
? |
Optional. Matches the preceding expression 0-1x. Equivalent to {0,1} |
{n} |
Matches n times |
{n, m} |
Matches at least n times but no more than m times |
{n,} |
Matches at least n times |
| Symbol | Matches |
|---|---|
. |
any character except newline |
\w |
any alphanumeric character including the underscore. Equivalent to [A-Za-z0-9_] |
\d |
digit character [0-9] |
\s |
whitespace and tabs, return, newline |
\W |
any non-word character. Equivalent to [^A-Za-z0-9_]. |
\D |
any non-digit character. Equivalent to [^0-9] |
\S |
any single character other than white space |
[abc] |
any of the characters in the brackets |
| Symbol | Meaning |
|---|---|
^ |
Matches the beginning of the string |
$ |
Matches the end of the string |
. |
Matches any single character, except for line breaks |
* |
Matches the string 0+ times or {0,} |
+ |
Matches the string 1+ times or {1,} |
? |
Optional. Matches the preceding expression 0-1x or {0,1} |
| Flag | Name | Purpose |
|---|---|---|
g |
global | Search for all matches |
i |
case sensitive | Ignore case when matching |
m |
multiline | Multi-line search |
u |
unicode | Treat pattern as a sequence of unicode code points |
y |
sticky | Anchors each match of a regular expression to the end of the previous match |