Regex Tools
Create, test and validate regular expressions
What are Regular Expressions?
Regular expressions (regex) are special patterns used to find and manipulate text. They help search for specific patterns like phone numbers, email addresses, etc.
Basic Regex Options:
Literal text to find
Controls how many times the pattern should appear
Advanced Regex Options:
Separate options with | (E.g.: +351|351 for /^(+351|351)/)
Separate groups with ; (E.g.: 9[1236][0-9]{7} for /^(9[1236][0-9]{7})$/)
Use expressions like [123] for sets or {n} for quantifiers
Use expressions like [123] for sets or {n} for quantifiers
💡 Why use Flags and Delimiters
g→ Global: searches for all occurrences, not just the first.m→ Multiline: makes^and$match the start and end of each line, not the whole text.i→ Ignore Case: ignores upper/lowercase (e.g.:/abc/imatches "ABC" or "abc").s→ Dot All: allows the dot.to also match line breaks (\n).\b→ Boundary: ensures the pattern is found only when isolated (e.g.:/\bcat\b/matches "cat" but not "concatenate").^→ Start: matches the start of the line (or text, withoutm).$→ End: matches the end of the line (or text, withoutm).
^ and $ are needed without g or m. Use i for case-insensitive matching and \b to avoid false positives in long texts.
Enter a complete regex pattern directly (ignores other options)
Examples:
- Email:
/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/ - Telemóvel PT:
/(\+351|351)?9[1236]\d{7}/- Apenas telemóveis (ex: 912345678, +351912345678) - Telefone PT (todos):
/(\+351|351)?[2-9]\d{8}/- Fixos e telemóveis (ex: 212345678, 912345678) - Telefone Brasil:
/(\+55|55)?\s?(\d{2})\s?9?\d{4}-?\d{4}/ - NIF Portugal:
/[1-9]\d{8}/- 9 dígitos, não começa com 0 - IBAN (Portugal e UE):
/([A-Z]{2}\d{2})(\s?\d{4}){4,7}\s?/- Aceita formato PT e europeu (ex: PT50 1234 5678 9012 3456 7890 1) - Cartão Cidadão PT:
/\d{8}[ -]?\d[ -]?[A-Z]{2}\d/- Ex: 12345678 9 ZZ0 - Código Postal PT:
/\d{4}-\d{3}/- Formato ####-### - CPF Brasil:
/\d{3}\.\d{3}\.\d{3}-\d{2}/ - CNPJ Brasil:
/\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}/ - CEP Brasil:
/\d{5}-?\d{3}/ - Data (DD/MM/YYYY):
/(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/\d{4}/ - URL (no meio do texto):
/(https?:\/\/)([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}([\/?#][^\s]*)?/ - Username:
/[a-zA-Z0-9_]{3,16}/- 3 a 16 caracteres alfanuméricos - Hexadecimal:
/#?[0-9A-Fa-f]{6}/- Cores hex com # opcional - Senha Forte:
/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}/- Mín. 8 chars (encontra no meio do texto) - Número Inteiro:
/-?\d+/- Aceita inteiros positivos ou negativos (ex: -42, 1500) - Número Decimal:
/-?\d+([.,]\d+)?/- Decimais com ponto ou vírgula (ex: 3.14, -2,5) - Placa de Matrícula PT (modelo novo):
/[A-Z]{2}-\d{2}-[A-Z]{2}/- Ex: AB-12-CD - Hashtag:
/#[A-Za-z0-9_]{2,30}\b/- Ex: #Portugal, #DevTools - IP Address:
/\b(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}\b/