Regex Tester (JavaScript)

Test a JavaScript regular expression against sample text.

What this regex tester does

This regex tester runs a JavaScript regular expression against your sample text and shows how many matches it found, followed by a list of every match. You can set flags such as case-insensitive or multiline mode, change the pattern and run it again until it matches exactly what you want. It runs in your browser using the same regular expression engine your JavaScript code uses.

It is for web developers writing validation and parsing code, QA engineers checking log formats, data analysts cleaning text, SEO specialists building filters, and anyone learning regular expressions.

How to use the regex tester

  1. Enter your regular expression in the Pattern field without the surrounding slashes. For example, type \d{3}-\d{4}, not /\d{3}-\d{4}/. The default pattern is \w+ (runs of word characters).
  2. Enter Flags. The default is g. Supported flags are g, i, m, s, u and y; other characters are ignored. The global flag is always applied so that all matches are listed.
  3. Paste your sample into the Text box.
  4. Click Submit.
  5. Read the number of matches and the list of matched strings. Adjust the pattern and submit again.

To keep the page fast, the tester reads the first 8,000 characters of your text and stops after 100 matches. If your pattern has a syntax error, you will see "That pattern is not valid."

Flags explained

  • g (global) – find all matches, not just the first.
  • i (ignore case) – letters match regardless of upper or lower case.
  • m (multiline) – ^ and $ match at the start and end of each line, not only of the whole text.
  • s (dotAll) – . also matches line breaks.
  • u (unicode) – treat the pattern as Unicode code points and enable escapes such as \p{L} for any letter.
  • y (sticky) – each match must start exactly where the previous one ended.

Examples

  • \b\d{4}-\d{2}-\d{2}\b – dates in YYYY-MM-DD format, such as 2026-10-18.
  • #[0-9a-fA-F]{6}\b – six-digit hex colour codes such as #1A2B3C.
  • https?://\S+ – rough match for web links in text.
  • ^ERROR.*$ with flags gm – every log line that starts with ERROR.
  • colou?r with flag i – both "color" and "colour", in any case.

Each item in the result list is the full text of one match. If a pattern matches the wrong thing, look at the list: it usually shows straight away whether the pattern is too greedy or too strict.

Common use cases

  • Building form validation patterns for postcodes, order numbers or usernames.
  • Extracting IDs, emails, URLs or prices from a block of text.
  • Testing log filters before using them in monitoring or search tools.
  • Preparing patterns for find-and-replace in a code editor or the Find and Replace tool.
  • Learning regex syntax with instant feedback.

Tips and common mistakes

  • Escape special characters. ., *, +, ?, (, ), [, ], {, }, |, ^, $ and \ have special meanings. To match a literal dot, use \..
  • Greedy vs lazy. <.+> matches from the first < to the last > on a line. Add ? to make it lazy: <.+?>.
  • Anchor your validations. For whole-value checks, wrap the pattern in ^ and $, otherwise "abc123xyz" passes a test for \d+.
  • Regex flavours differ. This tester uses JavaScript syntax. Python, PHP (PCRE), Java and .NET are similar but not identical, for example in lookbehind support, named groups and flags. Test in the target language before shipping.
  • Don't over-engineer. Fully validating emails or HTML with a regex is notoriously hard. Use a simple pattern for a sanity check and a proper parser or confirmation step for the rest.
  • Beware catastrophic backtracking. Nested quantifiers such as (a+)+ can make some regex engines extremely slow on certain inputs. Keep patterns specific.

Frequently asked questions

Which regex flavour does this tester use?

JavaScript (ECMAScript) regular expressions, as implemented by your browser.

Do I need to type the slashes around my pattern?

No. Enter only the pattern in the Pattern field and the flags in the Flags field.

Why does my pattern find only part of what I expect?

Check whether you need the m flag for line anchors, the s flag for dots across lines, or the i flag for case. Also check the 8,000-character and 100-match limits.

Does it show capture groups?

The result list shows the full text of each match. To check a group, temporarily make it the whole pattern, or test the group in your code.

What does \w match?

In JavaScript, \w matches ASCII letters, digits and the underscore. It does not match accented letters; use \p{L} with the u flag for letters in any script.

Is my text sent anywhere?

No. The pattern is run in your browser.

Related tools

  • Find and Replace – replace text, optionally with a regular expression.
  • Remove Duplicate Lines – clean up lists after extracting matches.
  • Sort Lines – sort extracted values A to Z or Z to A.
  • JSON Formatter – read structured data instead of parsing it with regex.
  • Word Counter – count words and characters in your sample text.