Advertisement

Regex Generator for Common Patterns

Generate a regular expression for emails, URLs, dates, IPs, phone numbers or your own words, with ready-to-paste JavaScript, Python, PHP, Java or C# code.

Only used by "Exact text" and "Any of these words". Separate words with commas.
How will you use it?
In "validate" mode every non-empty line is checked on its own.

Writing a regular expression from scratch is slow and easy to get subtly wrong. This generator gives you a tested pattern for the things developers match most often — emails, URLs, IPv4 addresses, dates, times, phone numbers, UUIDs, hex colours — or builds one from your own exact text or list of words, escaping the special characters for you. You also get a code snippet in the language you use and a live test against your own sample text.

How to use this tool

  1. Pick what you want to match, or choose "Exact text" / "Any of these words" and type your text.
  2. Choose Find to pull matches out of longer text, or Validate to check that a whole value has the right format.
  3. Tick "Ignore upper / lower case" if capitalisation should not matter.
  4. Press Calculate. Pick your language and copy the code; paste some real data into the test box to confirm it behaves as you expect.

Formula

Find mode: boundary + pattern + boundary (e.g. \b…\b). Validate mode: ^pattern$.

Boundaries such as \b or (?<!\d) stop a match starting or ending in the middle of a longer word or number. In validate mode the code uses each language's whole-string check (fullmatch in Python, matches() in Java, \z in .NET, the D modifier in PHP) so a trailing newline cannot slip through. Calculation runs in a worker and stops after two seconds.

Example

With Email address in find mode the pattern is \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b. On the text "Write to ann@example.com or bob.smith@mail.co.uk, not to bob@localhost." it finds 2 matches: ann@example.com and bob.smith@mail.co.uk. bob@localhost is skipped because it has no dot-and-letters ending such as .com.

Frequently asked questions

Is the email pattern RFC 5322 compliant?

No. This is a deliberately limited ASCII format heuristic; it can accept malformed addresses and reject valid quoted or international addresses. Use a mail-aware parser and confirmation workflow for real accounts.

Can a regex check that a date really exists?

Not sensibly. The date patterns check the format and the month and day ranges, so 31/02/2026 still passes. Parse the value with a date library to reject impossible dates.

Why does the password pattern only work in validate mode?

It uses lookaheads that each scan the whole value for a lowercase letter, an uppercase letter, a digit and a symbol. Inside longer text that question has no clear meaning, so it is always anchored. It checks composition, not resistance to guessing.

Will the pattern work in my language?

The patterns avoid engine-specific features. The lookbehind used for phone numbers and plain numbers works in modern JavaScript, Python, PHP (PCRE), Java and .NET.

Sources

Last updated: 2026-10-30

Advertisement