Free regex generator

Regex generator and test it on your text

Choose a template such as email, US phone or IPv4, switch anchors and flags, and see every match light up in your own text before you copy the pattern.

  • Free, no sign-up
  • Your text stays in this browser
  • Matches update as you type

From a template to a tested pattern in four moves

The pattern and the highlighted matches are redrawn after every change, so you see what you will copy.

  1. Step 01

    Paste a sample of your text

    Drop in the lines you want to search. The field is optional on the first screen and can be filled later.

  2. Step 02

    Pick the template that fits

    Email, US, Spanish or German phone and postal codes, DNI/NIE/NIF, URL, dates, IPv4, hex color, integer, identifier or time. Nothing is chosen for you.

  3. Step 03

    Set anchors, flags and the variant

    Turn on ^ and $ to match a whole value, add g, i or m, and choose a variant such as ZIP with four extra digits.

  4. Step 04

    Check the matches, then copy

    Highlighted matches and a counter show the result. Copy takes the literal, and Share link rebuilds your state anywhere.

What you get with every pattern

  • Sixteen ready templates, including Spanish and German phone, postal code and ID formats
  • Anchors and the g, i and m flags as simple checkboxes
  • Variants where they matter, such as ZIP with five or nine digits
  • Live highlighting and a match counter on your own text
  • The full /pattern/flags literal and the bare pattern string, side by side
  • One-tap Copy and Clear
  • A share link that carries your template, options and text in the address
  • Your last setup remembered in this browser

How the templates, anchors and flags work

A regular expression is a compact description of text you want to find. Each template here is a pattern written by hand for one kind of value and checked against valid and invalid examples. The pattern is built in your browser when you pick the template, so the literal on screen is exactly what the JavaScript RegExp engine will run.

Reading a pattern is easier in pieces. Square brackets hold a set of allowed characters, so [0-9A-Fa-f] means any hexadecimal digit. A number in curly braces says how many times the piece repeats, so \d{5} is five digits in a row. A plus sign means one or more, a question mark means optional, and a group in parentheses with ?: in front lets you repeat or alternate a part without capturing it.

Anchors decide whether the pattern may match inside a longer text. With anchors off, the template searches your text and finds every value, using look-arounds so that a ZIP code does not match the first five digits of a longer number. With anchors on, the pattern is wrapped in ^ and $ and must match the whole string, which is what you want when validating a single form field. Because the m flag changes what ^ and $ mean, turning it on lets each line of a multi-line text match as a whole.

The three flags are g, i and m. The g flag finds all matches instead of only the first, so the counter shows every hit. The i flag ignores letter case, which helps with hex colors and email addresses typed in capitals. The m flag makes ^ and $ work per line. Flags appear after the closing slash of the literal, for example /pattern/gi.

Some templates have a variant. US phone can include parentheses and separators or be digits only. US ZIP can be five digits, five plus four, or either. URL can allow http and https or https only. Time can be 24-hour or 12-hour with AM or PM. Changing the variant rewrites the pattern at once.

What is saved. Your template, options, flags and test text are kept in this browser after every change, and nothing is sent to a server. The share link stores the same state inside the part of the address after the # sign, which browsers never send to a website, and it carries up to a few thousand characters of text.

Worked example: an email pattern on a short text

These values are produced by the same code as the tool, using the Email template on the text “Write to a@b.com or x.y@mail.org, not foo@”.

Generated literal (g flag)/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g
Matches without anchors2
Matches with anchors0
Matched valuesa@b.com, x.y@mail.org
IPv4 template on “10.0.0.1 and 999.1.1.1”1 match: 10.0.0.1

The last item, foo@, has no domain, so it is not counted. With anchors on, the whole sentence would have to be one email address.

Where a template is not enough

  • Patterns follow JavaScript RegExp only. Other dialects such as PCRE, Python or .NET can differ in syntax and flags.
  • Templates catch typical values, not every legal one. The email pattern, for example, is not a full check against the email standard.
  • When you need your own rule, write the pattern by hand and test it in your code.

Regex generator questions

Which regex flavor does it produce?

JavaScript. Patterns run on the RegExp engine of your browser and work in Node.js and in front-end code.

Does my text leave my device?

No. Matching happens in your browser. The share link keeps the text after the # sign, which is never sent to a server.

What do the anchors do?

They wrap the pattern in ^ and $, so the whole string must match. Without them the pattern finds values inside longer text.

Why does the g flag matter?

With g the search returns every match. Without it only the first match is found and counted.

Why does the IPv4 template skip 999.1.1.1?

Each octet is limited to 0–255, so 999 cannot be part of an address and only the valid address in your text is highlighted.

Can I use the pattern outside the browser?

Yes. Paste the literal into JavaScript or Node.js code, or pass the pattern string and flags to new RegExp.

How do I share my setup?

Press Copy share link and send the address. Opening it restores the template, options and text.

Need a pattern you can trust?

Pick a template, check it on your text and copy the literal in a few seconds.

Start building my regex

About ToolperLast updated: Privacy