Regex Creator
Expression
/
/
Test String
Quick Tokens
Code Generator
Ready Examples
Click on an example to fill the expression, flags and text, and generate code automatically.
Complete Regex Creator Guide
Use this tool to build and test regular expressions and generate code snippets in multiple languages. Below is a practical guide explaining each screen element, with usage tips and best practices.
Expression and Flags
- Expression: field where you write the regex. Ex.:
\\b\\d{2}/\\d{2}/\\d{4}\\b. - Flags: behavior control. i ignore case, m multiline, s dotall, u unicode. The flag g indicates global search in environments that support it; when it doesn't exist, the generator uses full scan methods (like
findAll). - Compatibility: when selecting a language, the generator maps the flags to equivalent options (e.g.,
re.IGNORECASEin Python,Pattern.CASE_INSENSITIVEin Java).
Example Text
- Type or load text snippets to validate matches and test replacements.
- Use cases with format variations to evaluate robustness and false positives.
Quick Tokens
- Insert common tokens without memorizing everything: anchors (
^,$), boundaries (\\b), classes (\\d,\\w,\\s), groups and lookarounds ((?=),(?!),(?<=),(?<!)). - Helps compose patterns quickly and with fewer syntax errors.
Ready Examples
- Automatically fills expression, flags, and text for common cases: dates, email, URLs, CPF/CNPJ, strict IPv4, Mercosul Plate, cards with Luhn, and more.
- Use these examples as a base and refine according to your business rule.
Code Generator
- Select the language and copy/download the snippet. The generator chooses idiomatic APIs (
matchAll,finditer,Regex,NSRegularExpression, etc.). - Modes: Match (Find) prints positions and values; Replace applies the regex and returns the changed text.
- Replacement Placeholders: vary by language (
$&,$1,${1}). Type the desired format in the replacement field according to the selected language.
Best Practices
- Delimit context: use
\\b, anchors, and groups to avoid unwanted captures. - Prefer specific quantifiers: replace
.*with controlled ranges (e.g.,[0-9]{2,4}). - Avoid catastrophic backtracking: minimize nested repetitions with broad patterns; test with long inputs.
- Compatibility: not all features exist in all engines (named groups and lookbehinds, for example). Adjust the pattern to the destination.
- Validation: for documents with check digits (CNPJ/CPF/Cards), combine regex with verification functions (Luhn, DV).
Productivity Tips
- Start with ready examples and adapt the quick tokens.
- Test in different languages to check flag and group compatibility.
- Save the generated snippet for documentation and reuse in projects.