SupperTools

Useful Online Tools & Utilities to Make Everyday Tasks Easier.

Regex Tester to Test Patterns Against Real Text Live

Write a regular expression and watch matches highlight in real time against your own sample text, with a cheatsheet for classes, quantifiers, anchors and flags.

/
/
Results
No matches found.

Try adjusting your regex pattern or test string.

Regex Cheatsheet
.Any character except newline
\wWord (A-Z, a-z, 0-9, _)
\dDigit (0-9)
\sWhitespace (space, tab, etc)
[abc]Any of a, b, or c
[^abc]Not a, b, or c
*0 or more
+1 or more
?0 or 1
{3}Exactly 3
{3,}3 or more
{3,5}Between 3 and 5
^Start of string / line
$End of string / line
\bWord boundary
(abc)Capture group
(?:abc)Non-capturing group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
gGlobal match
iCase-insensitive
mMulti-line
uUnicode
sDot matches newline

Every developer knows the moment: a regular expression that looks right, matches nothing, or matches far too much, and the only way to find out is to run it against real text. A regex tester gives you that feedback instantly, highlighting matches as you type and letting you refine the pattern character by character until it selects exactly what you intended and nothing else.

What the Regex Tester Does

A regular expression is a compact language for describing text patterns: this many digits, that set of letters, a word at the start of a line, and so on. This tester lets you write a pattern, apply it to sample text, and watch the matches light up in real time, with syntax highlighting to make the pattern itself easier to read. A built in cheatsheet sits alongside, organised into sections such as character classes, quantifiers, anchors, groups and lookaround, and flags, so the piece of syntax you half remember is one click away instead of a search through documentation. It answers the practical question every regex writer asks a dozen times a day: does this pattern match what I think it matches?

Features of the Regex Tester

  • Real time matching with syntax highlighting, as described for this tool, so results update while you edit.
  • A built in cheatsheet with tabs for Character Classes, Quantifiers, Anchors, Groups & Lookaround and Flags.
  • Space to test against your own sample text, ideally real examples copied from the data you will actually process.
  • Immediate visibility of partial and multiple matches, which is where most regex mistakes hide.

How to Use the Regex Tester

  1. Paste or type the text you want to search into the sample text area, using realistic examples including cases that should not match.
  2. Type your pattern into the pattern field, starting simple, for example a plain word or a single character class.
  3. Watch the highlighted matches and compare them against the results you expected.
  4. Add one element at a time, such as a quantifier or an anchor, checking after each change that the matches still make sense.
  5. Open the Character Classes or Quantifiers cheatsheet tabs whenever you need the exact syntax for something.
  6. Use the Flags section to switch behaviour such as case insensitive matching or multiline anchors, and observe how the matches change.
  7. When the pattern matches all of your positive examples and none of your negative ones, copy it into your code or editor.

Worked Example: Building a Pattern Piece by Piece

Suppose you want to match order codes made of two capital letters followed by four digits, like AB1234. Start with the character class for a capital letter, [A-Z], and add the quantifier for exactly two of them: [A-Z]{2}. Test it against the sample text "Order AB1234 shipped, code XY99 rejected" and it highlights AB and XY. Now add the digits: [A-Z]{2}[0-9]{4} using \d as the shorter digit class gives [A-Z]{2}\d{4}, which matches AB1234 but not XY99, exactly right. Finally anchor it when validating a whole field: ^[A-Z]{2}\d{4}$ forces the entire string to be the code and nothing else. A second classic: finding duplicated words with a backreference, (\w+)\s+, which matches "the the" in a sentence because  repeats whatever the group captured. For a deeper reference while you work, the MDN guide to regular expressions explains the same syntax in depth, and on this site the text replacer and JSON validator handle neighbouring text jobs.

Where Regex Testing Earns Its Keep

Form validation is the everyday case: postcodes, phone formats, and product codes all reduce to patterns that must accept the right shapes and reject the rest. Log analysis is another, where one good pattern pulls error lines, IP addresses or timestamps out of thousands of lines of noise. Editors and IDEs use the same syntax for advanced find and replace, so a pattern proven here can rename variables, reformat dates or strip markup across a whole project. Data cleaning work, splitting imported fields, checking email shaped strings, and extracting values from scraped text all depend on patterns that were tested against realistic samples before they were trusted.

Tips, Limitations and Common Mistakes

The classic mistake is a greedy quantifier: .* happily swallows the whole line when you wanted the smallest match, which is what lazy quantifiers like .*? exist for. Forgetting to escape a dot is another; an unescaped dot matches any character, so a pattern meant to find a file extension also matches lookalike text. Always include negative examples in your test text, strings that must not match, because a pattern is only correct when it fails in the right places too. Remember that regex flavours differ slightly between languages and tools, especially for lookaround and named groups, so confirm the feature you used exists in your target environment. Finally, know when to stop: a pattern that tries to parse full HTML or validate every rule of an email address becomes unmaintainable, and a small piece of ordinary code is often the better tool.

Frequently Asked Questions About Regex Testing

What do flags like i, g and m actually do?

The i flag makes matching case insensitive, g finds every match instead of stopping at the first, and m makes the ^ and $ anchors match at line boundaries as well as the start and end of the whole text.

Why does my pattern match more than I expected?

Usually because a quantifier is greedy, a dot is unescaped, or the pattern is not anchored. Add ^ and $ when the whole string must fit, escape literal dots with a backslash, and switch to a lazy quantifier when you want the shortest match.

What is the difference between a character class and a group?

A character class like [0-9] matches exactly one character from a set. A group in parentheses bundles several elements together so quantifiers and alternation apply to them as a unit, and so the matched part can be captured and reused.

Can I test patterns for languages other than JavaScript?

Most everyday syntax is shared across flavours, so patterns built from classes, quantifiers, anchors and groups usually transfer well. Check features like lookbehind and named groups against your language, since support varies.

How do I match a literal character that is special in regex?

Escape it with a backslash. A backslash before a dot, star, plus, question mark, brackets or the backslash itself tells the engine to treat that character as ordinary text rather than syntax.

Test the Pattern Before You Trust It

The regex tester replaces guess, run and hope with a tight loop of write, watch and refine. Build patterns in small steps, test them against examples that should fail as well as examples that should pass, and the expression you finally copy into your project will already have earned your trust.

Related Tools