Testa espressioni regolari JavaScript con evidenziazione dei match in tempo realeTest JavaScript regular expressions with real-time match highlighting
Le espressioni regolari (regex) sono pattern per cercare, validare e trasformare testo. In JavaScript sono supportate nativamente con i metodi match(), replace(), test() e matchAll().
I flag modificano il comportamento: g trova tutti i match (non solo il primo), i ignora maiuscole/minuscole, m tratta ogni riga come inizio/fine stringa, s fa corrispondere il punto anche ai newline.
Regular expressions (regex) are patterns for searching, validating and transforming text. In JavaScript they're natively supported via the match(), replace(), test() and matchAll() methods.
Flags change the behavior: g finds all matches (not just the first), i ignores case, m treats each line as a string start/end, s makes the dot also match newlines.
Come validare un'email con regex in JavaScript?How do I validate an email with regex in JavaScript?
Una regex affidabile per email Γ¨ /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/. Le regex non possono garantire al 100% la validitΓ β per farlo occorre inviare un'email di verifica.A reliable email regex is /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/. Regex can't guarantee 100% validity β for that you need to send a verification email.
Cosa sono i gruppi di cattura?What are capture groups?
Le parentesi () creano gruppi che catturano la parte corrispondente del testo. Puoi referenziarli con $1, $2... nel replace, o leggerli con match()[1]. I gruppi non-catturanti usano (?:...).Parentheses () create groups that capture the matching part of the text. You can reference them with $1, $2... in replace, or read them with match()[1]. Non-capturing groups use (?:...).