| # | Content | Index | Length | Groups |
|---|
| Expression | Description | Example |
|---|---|---|
. | Matches any character except newline | a.c |
\d | Matches digits (0-9) | \d+ |
\D | Matches non-digit characters | \D+ |
\w | Matches letters, digits, and underscores | \w+ |
\W | Matches non-word characters | \W+ |
\s | Matches whitespace characters (space, tab, newline) | \s+ |
\S | Matches non-whitespace characters | \S+ |
\t | Matches tab character | \t |
\n | Matches newline character | \n |
\r | Matches carriage return | \r |
^ | Matches start of string | ^hello |
$ | Matches end of string | world$ |
\b | Matches word boundary | \bcat\b |
\B | Matches non-word boundary | \Bcat\B |
* | Matches previous element zero or more times | a* |
+ | Matches previous element one or more times | a+ |
? | Matches previous element zero or one time | colou?r |
{n} | Matches exactly n times | \d{6} |
{n,} | Matches at least n times | \d{2,} |
{n,m} | Matches between n and m times | \d{2,5} |
*? | Non-greedy match | <.*?> |
[] | Character set | [abc] |
[^] | Negated character set | [^0-9] |
[a-z] | Character range | [a-z]+ |
() | Capturing group | (\d+) |
(?:) | Non-capturing group | (?:abc) |
(?=) | Positive lookahead | \d(?=px) |
(?! ) | Negative lookahead | \d(?!px) |
(?<=) | Positive lookbehind | (?<=¥)\d+ |
(?<!) | Negative lookbehind | (?<!¥)\d+ |
| | Logical OR | cat|dog |
\ | Escapes special characters | \. |
\uXXXX | Unicode character | \u4e2d |
\xXX | Hexadecimal character | \x41 |
\1 | Reference to first capturing group | (a)\1 |
$1 | Reference first group in replacement | [$1] |