Guida Rapida
Guida Rapida Regex
Un riferimento completo per la sintassi delle espressioni regolari da consultare quotidianamente.
Classi di Caratteri
| Sintassi | Descrizione |
|---|---|
. | Any character except newline |
\d | Any digit (0-9) |
\D | Any non-digit |
\w | Word character (letter, digit, underscore) |
\W | Non-word character |
\s | Any whitespace (space, tab, newline) |
\S | Any non-whitespace |
[abc] | Any one of a, b, or c |
[^abc] | Any character except a, b, or c |
[a-z] | Any character in range a to z |
[0-9] | Any digit (same as \d) |
Quantificatori
| Sintassi | Descrizione |
|---|---|
* | Match 0 or more times (greedy) |
+ | Match 1 or more times (greedy) |
? | Match 0 or 1 time (optional) |
{n} | Match exactly n times |
{n,} | Match n or more times |
{n,m} | Match between n and m times |
*? | Match 0 or more times (lazy) |
+? | Match 1 or more times (lazy) |
?? | Match 0 or 1 time (lazy) |
Ancore e Confini
| Sintassi | Descrizione |
|---|---|
^ | Start of string (or line with m flag) |
$ | End of string (or line with m flag) |
\b | Word boundary |
\B | Non-word boundary |
Gruppi e Riferimenti Indietro
| Sintassi | Descrizione |
|---|---|
(abc) | Capturing group |
(?:abc) | Non-capturing group |
(?<name>abc) | Named capturing group |
\1 | Backreference to group 1 |
\k<name> | Named backreference |
(a|b) | Alternation (OR) |
Lookahead e Lookbehind
| Sintassi | Descrizione |
|---|---|
(?=abc) | Positive lookahead — followed by abc |
(?!abc) | Negative lookahead — NOT followed by abc |
(?<=abc) | Positive lookbehind — preceded by abc |
(?<!abc) | Negative lookbehind — NOT preceded by abc |
Flag
| Sintassi | Descrizione |
|---|---|
g | Global — find all matches |
i | Case-insensitive |
m | Multiline — ^ and $ match line boundaries |
s | Dotall — . matches newlines too |
u | Unicode mode |
v | Unicode sets (extended) |
d | Generate indices for matches |
y | Sticky — match from lastIndex only |
Caratteri Speciali
| Sintassi | Descrizione |
|---|---|
\n | Newline |
\r | Carriage return |
\t | Tab |
\0 | Null character |
\\ | Literal backslash |
\. | Literal dot |
\[ | Literal opening bracket |