What is a regular expression?
A regular expression (regex) is a pattern that describes a set of strings: character classes ([0-9]), quantifiers (+, *, {2,4}), anchors (^, $) and groups combine into rules that a matcher applies to text. Regexes validate formats, extract fields and drive search-and-replace; the JavaScript flavour is defined by ECMA-262, and small differences between engines are why a pattern should be tested with the engine that will run it.
Read the guide: Regular Expressions (Regex) for Beginners
How to use Regex Generator
- Pick a pattern from the library, or type a custom pattern or a literal string.
- Add flags (for example i) and choose whether to anchor the whole string.
- Paste sample values one per line to confirm the pattern behaves as expected.
- Copy the regex or the code snippet for your language.
Regex Generator features
- Library of 40+ patterns with self-tests: email, URL, IPv4/IPv6, UUID, semver, ISO dates, IBAN, credit cards, Saudi/Jordan/UAE/India phone numbers, national IDs and more
- Literal-text mode that escapes special characters automatically
- Whole-string anchoring and extra flags in one click
- Sample strings tested line by line with a match / no-match verdict
- Ready-to-paste snippets for JavaScript, TypeScript, Python, Java, C# and Go
- Browse the whole library as a downloadable table
Regex Generator example
Validate Saudi mobile numbers
Input:
Library: Saudi mobile (+966 5X)
Samples:
+966501234567
0551234567
+962791234567Output:
/^(?:\+966|00966|0)?5[0-9]{8}$/
+966501234567 → ✓ match
0551234567 → ✓ match
+962791234567 → ✗ no matchFrequently asked questions about Regex Generator
What patterns are in the library?
More than 40 tested patterns: email, URL, domain, slug, IPv4/IPv6, MAC, port, UUID, ULID, semver, hex colour, JWT, ISO dates and times, credit cards, IBAN (generic and Saudi), Saudi and Jordanian mobile numbers, Saudi national ID, UAE and Indian mobiles, E.164, Arabic and Devanagari text, passwords, base64, hashes and more.
Are the library patterns validated?
Every pattern ships with strings it must match and strings it must reject, and the unit-test suite verifies all of them on every build.
Can I match a literal string that contains special characters?
Yes — type it in the "Literal text" field and the generator escapes characters such as . * ? ( ) [ ] so they match exactly.
Which programming languages are supported for the snippet?
JavaScript, TypeScript, Python, Java, C# and Go. Flags are translated to the equivalent options (for example re.IGNORECASE or RegexOptions.IgnoreCase).
Should I rely on a regex alone to validate an IBAN or credit card?
No. The patterns check the format only; always add the checksum (MOD-97 for IBAN, Luhn for card numbers) in your application logic.
Technical notes
Every library entry carries positive and negative examples. A unit test compiles each pattern and asserts all examples, so a broken pattern fails the build rather than reaching users. Patterns deliberately validate format only; checksums such as IBAN MOD-97 and Luhn belong in application code.
References
- ECMAScript® Language Specification (ECMA-262)The JavaScript language standard, including the RegExp grammar and semantics, JSON.parse/JSON.stringify and the Date object.
- Regular expressions — JavaScript guide — MDNA practical reference for regular-expression syntax as implemented in JavaScript engines: character classes, groups, quantifiers, flags.
- OWASP Cheat Sheet Series: Input ValidationAllow-list validation, syntactic vs. semantic checks, and why client-side validation is never a security control.