Skip to content
MagicWebBox
Sign in

Regex Generator

Generate custom regular expressions based on your criteria.

Settings

or choose pattern

or compose your regex

Result

The result will appear here.

Test the expression

Flags

About this tool

The regex generator offers three ways to get a JavaScript regular expression: pick a ready-made pattern (email, phone number, URL, DD/MM/YYYY date, time, password, IP, postal code, credit card, hex color, file extension), type a text to match literally with its special characters escaped, or check the character types you want to allow.

The resulting expression is wrapped in ^ and $ so it validates a whole value, such as a form field. It is then loaded into the tester, where you can edit it, toggle the i, m, s and u flags, and paste sample text: matches are highlighted and captured groups are listed in a table. For multi-line text, turn on the m flag so each line is checked.

How to use it

  1. Type a text in “Enter text to match (exact match)”, or pick a preset in “Select pattern type”.
  2. Or check the character types you need, for example “Include digits (0-9)”.
  3. Click “Generate Regex”, then “Copy Regex”.
  4. In “Test the expression”, paste some text into “Test text” to see the matches highlighted.

Frequently asked questions

Do the presets validate every format?

No, they are simple patterns. The postal code expects five digits, the date follows DD/MM/YYYY between 1900 and 2099 without checking how many days a month has, the IP preset only covers IPv4, and the credit card one checks length, not the Luhn checksum.

Which languages does the expression work in?

It is generated and tested with the JavaScript engine, in /pattern/flags form. Its syntax, character classes and lookaheads, also works in Python, PHP or Java, but remove the surrounding slashes and double-check escaping before using it elsewhere.

What does the expression tester do?

It runs the expression on your text in global mode and highlights every match. The i (ignore case), m (multiline), s (dot matches line breaks) and u (Unicode) flags can be toggled separately. Numbered and named groups are listed, up to 1,000 matches.

Is my test text sent anywhere?

No. Generation and testing run in your browser, with no network request, and nothing is saved: the test text and the expression are gone when you leave the page.