🔒 Processed locally in your browser — no data uploaded
← Back to Home

Regex Tester

Regular expression
/ /
Test text
Result

What the Regex Tester does

This page runs a JavaScript regular expression against text you paste and reports how many places that pattern matches, plus what it caught. It uses the browser's own RegExp engine, the same code behind String.match in Chrome, Edge and Firefox, so a pattern that works here behaves the same way inside your own scripts. Nothing leaves the page: the expression and the sample text are held in memory by the tab you have open.

Two buttons give two different answers. Test Match confirms the pattern compiles and counts the hits; Show Matches prints each matched substring on its own numbered line, which is what you want when a greedy pattern returns more than you expected. A pattern that will not compile returns the engine's own error text instead of a vague failure note, and the line under the result echoes the pattern and flags exactly as the tool parsed them.

How to use it

  1. Type the pattern bodyEnter the expression between the two slashes without writing the slashes yourself, because the tool supplies the delimiters when it builds the RegExp object. An empty box returns a request for input rather than a list of hits.
  2. Choose your flagsTick g to scan for every match, i to ignore letter case, m to treat each line as its own anchor point. The default state has g already on, and unticking it caps the reported count at one.
  3. Paste the test textDrop in a log snippet, a CSV field or a paragraph of prose. Matching runs against the whole textarea as a single string with its line breaks intact, so anchors behave the way they would in code.
  4. Count, then list hitsPress Test Match for a total and Show Matches for the substrings themselves. Clear wipes the pattern, the sample text and the result area in one click, and the sample is not restored afterwards.

Options and formats

Global flag (g)Leaves the counter running through the entire text. Uncheck it when you only care whether the pattern appears at all, since the report then stops at the first hit and ignores the rest.
Case-insensitive flag (i)Widens every letter in the pattern to accept both cases, so [a-z]+ also swallows capitals. Useful for user-entered text where casing is unpredictable, risky where a difference in case carries meaning.
Multiline flag (m)Makes ^ and $ anchor to the start and end of each line rather than the whole string. Without it, five pasted lines form one string, and a caret will only ever match at the very beginning.
Match listingPrints each hit on its own numbered line in the order found. Zero-width matches, such as a bare word boundary, show up as entries with no visible text, which is the engine reporting a match rather than a fault.

Things to watch out for

Greedy quantifiers swallow too muchA pattern like .* between two markers grabs everything up to the final marker rather than the next one. Swap it for .*? to get the shortest possible match, then compare the two listings side by side to see the difference.
Backslashes get eaten twiceIn the pattern box you type \d for a digit. The same expression inside a JavaScript string literal needs two backslashes, because the string parser consumes one first. Test the exact literal your code will carry, not just the readable form.
One match reported without gThe counter leans on String.match, so an unticked g flag caps the number at one no matter how many times the pattern occurs. When a count looks suspiciously small, check the flag boxes before rewriting the expression.
Nested quantifiers can hang the tabPatterns such as (a+)+ against a long non-matching string trigger catastrophic backtracking, and the browser will spin without finishing. If the page stops responding, reload it and simplify the expression before trying again.

Frequently asked questions

How do I test a pattern that contains slashes?

Do not wrap the expression in slashes yourself, because the tool adds those delimiters. Type the body only, so a date pattern becomes \d{2}/\d{2}/\d{4}, with each forward slash treated as a literal character to match rather than as a boundary between pattern and flags.

Why does my escaped pattern work in the console but fail here?

This box feeds text straight into the RegExp constructor, while a console or a source file may hold the pattern inside a string that consumes backslashes first. Anything needing double escaping in code, such as \s or \w, is typed once here. When a pattern fails, the error message names the position the parser gave up on.

Can I see where each match sits in the text?

No, the listing prints matched substrings in order without character offsets. A workaround is to widen the pattern with surrounding context, for example matching the label in front of a value as well, since the hits appear in the order the text runs, left to right and top to bottom.

Which regex features are available here?

Anything the installed browser supports: character classes, quantifiers, alternation, anchors, numbered and named groups, lookahead, and Unicode property escapes. Lookbehind and the dotAll flag work in current Chrome, Edge and Firefox builds but not in older Safari, so check there if the pattern is bound for production.

Does the tester show replacement output?

No, this page only matches. Substitution rules differ between languages, so a replacement string that works in JavaScript is not guaranteed to behave the same in Python, PHP or Java, and testing it here would give false confidence. Use a scratch script in the target language for replacements.

How much text can I paste in?

The textarea accepts whatever you paste, but every check rescans the entire string, so a multi-megabyte log will feel sluggish and a pathological pattern can lock the tab. For large files, narrow the input first with grep or an editor search, then paste the few relevant lines.