top of page

What this regex tester does

A regular expression (regex) is a compact pattern for finding or validating text. This tester lets you type a pattern and some sample text and see every match highlighted as you type, along with captured groups. It runs entirely in your browser using the JavaScript regex engine, so nothing you paste is sent to a server.

How to use it

  1. Type your pattern in the expression box without the surrounding slashes.

  2. Choose flags: g (find all matches), i (ignore case), m (^ and $ match at line breaks), s (dot matches newlines).

  3. Paste test text into the input area. Matches are highlighted and listed with their position and any capture groups.

  4. Adjust the pattern until it matches what you want and nothing else, then copy it into your code.

Worked example

Say you need to pull dates in the form YYYY-MM-DD out of a log file. Use this pattern with the g flag:

(\d{4})-(\d{2})-(\d{2})

Test text: Backup ran 2026-10-03, failed 2026-10-04, ran again 2026-10-05.

  • There are 3 matches: 2026-10-03, 2026-10-04 and 2026-10-05.

  • For the first match, group 1 is 2026, group 2 is 10 and group 3 is 03.

Note that this pattern would also accept 2026-13-45. A regex checks shape, not meaning. If you need a real date check, match the shape with regex and then validate the values in code.

How regex matching works

The engine walks through the text from left to right, trying to match the pattern at each position. Building blocks you will use most:

  • \d a digit, \w a letter, digit or underscore, \s whitespace, . any character.

  • * zero or more, + one or more, ? optional, {n,m} between n and m times.

  • [abc] one of a set, [^abc] anything except the set.

  • ^ and $ anchor to the start and end, \b a word boundary.

  • ( ) captures a group, (?: ) groups without capturing, | means "or".

Tips and common mistakes

  • Escape special characters. To match a literal dot, write \.. An unescaped . matches anything, so example.com also matches "exampleXcom".

  • Greedy vs lazy. <.*> on "<b>hi</b>" matches the whole string. Use <.*?> to stop at the first closing bracket.

  • Anchor validation patterns. Without ^ and $, a pattern for "5 digits" also accepts "abc12345xyz".

  • Forgetting the g flag returns only the first match.

  • Engines differ. JavaScript, Python, PCRE and .NET support slightly different features (lookbehind, named groups, possessive quantifiers). Test in the language you will deploy to.

  • Do not parse HTML or JSON with regex beyond quick searches; use a proper parser.

Frequently asked questions

Why does my pattern work here but not in Python?

Syntax differs between engines. Python, for example, uses its own flags and named group syntax (?P<name>...). Recheck special features when moving between languages.

How do I match a whole line only?

Wrap the pattern in ^ and $ and turn on the m flag so they apply to each line.

Who it is for

Developers writing validation or search code, analysts cleaning data, and anyone learning regex who wants instant feedback on what a pattern really matches.

bottom of page