Free calculatorLive resultsSteps and sourcesEmbed on your site, free

Regular Expression Calculator

Regular Expression Tester works out Match found and First match from Regular expression, Text to search and Work budget (simulation steps). The default figures on this page give match found of yes; change any entry and the result, the working and the sources update together.

Match found
yes
Regular Expression Tester
First match
555-0199
Match starts at index
5
Match ends before index
13
Gave up (budget exhausted)
no
Simulation steps used
68
Compiled instruction count
9
Worked out from Ken Thompson, "Programming Techniques: Regular expression search algorithm", Communications of the ACM 11(6), 1968 and 1 other source.
This tester is deliberately not JavaScript-compatible on two points: it matches leftmost-longest rather than leftmost-first, and it refuses backreferences and lookaround outright. A pattern that works here may behave differently in a backtracking engine, and one that hangs a backtracking engine will finish here.

Your figures

Updates as you type
Literals, ., character classes, groups, alternation, * + ? {m,n}, anchors ^ $, and \d \w \s. Negated shorthands such as \D work outside brackets but are rejected inside them. No slashes or flags.
The search stops and reports "gave up" if it would take more work than this. It protects the page, not the answer.

How this is worked out

2 steps
  1. Compiled "\d{3}-\d{4}" to 9 NFA instructions.
  2. Leftmost-longest match at [5, 13): "555-0199" in 68 steps.

Its 3 worked examples are re-run on every release, last on 15 September 2026. What changed

Sources and references

2 sources
Ken Thompson, "Programming Techniques: Regular expression search algorithm", Communications of the ACM 11(6), 1968
The NFA simulation used here: advance a set of states one character at a time, so exponentially many match paths cost only linearly many states.
Russ Cox, "Regular Expression Matching Can Be Simple And Fast"
Why backtracking engines hang on patterns like (a+)+b and the Thompson construction does not.

What the Regular Expression Tester calculates

Tests a regular expression against a piece of text with a linear-time engine that cannot hang: it simulates all match paths at once instead of backtracking, so hostile patterns like (a+)+b finish in milliseconds. Matching is leftmost-longest, which can pick a longer match than JavaScript would. Backreferences and lookaround are refused rather than faked.

How to use this Regular Expression Tester

Enter Regular expression, Text to search and Work budget (simulation steps). Match found updates as you type, and “Use a worked example” loads checked figures you can adjust. Change one figure at a time to see what drives the result.

How the result is worked out

Open “How this is worked out” beside the result for the step-by-step calculation behind Match found, First match and Match starts at index.

The method follows Ken Thompson, "Programming Techniques: Regular expression search algorithm", Communications of the ACM 11(6), 1968 and Russ Cox, "Regular Expression Matching Can Be Simple And Fast".

A phone-shaped pattern finds its span example

With Regular expression: \d{3}-\d{4}, Text to search: call 555-0199 today, the calculator returns Match found: yes, First match: 555-0199, Match starts at index: 5. This example is checked against an independent source in the test suite.

What you can compare

Change one input at a time to see how it affects Match found, First match and Match starts at index. The inputs you can vary are Regular expression, Text to search and Work budget (simulation steps).

Understanding Match found, First match and Match starts at index

This tester is deliberately not JavaScript-compatible on two points: it matches leftmost-longest rather than leftmost-first, and it refuses backreferences and lookaround outright. A pattern that works here may behave differently in a backtracking engine, and one that hangs a backtracking engine will finish here.

Results are general information, not financial, tax, legal, medical or engineering advice. Check any decision that matters with a qualified professional.

Embed this calculator on your website

Copy this code into any page. The calculator appears with the figures currently entered, sizes itself to fit, and a small credit line links back here. Free, no account, no ads inside it, no tracking of your readers. Set your own figures and fixed fields; Personal removes the credit line, sets your colour and shows you which sites use it.

Preview

See something wrong? Report a problem with this calculator

Frequently asked questions

How to test a regular expression?

Tests a regular expression against a piece of text with a linear-time engine that cannot hang: it simulates all match paths at once instead of backtracking, so hostile patterns like (a+)+b finish in milliseconds. Open “How this is worked out” beside the result to see each step for your own figures.

What is the best online RegEx tester?

On the figures this page opens with, the match found is yes. No single number fits everyone: it follows Regular expression, Text to search and Work budget (simulation steps), so enter your own above and the answer updates as you type.

What are the benefits of using a regular expression tester?

It needs Regular expression, Text to search and Work budget (simulation steps). Nothing else is required, and the figures stay in your browser.

What information do I need for the Regular Expression Tester?

You need Regular expression, Text to search and Work budget (simulation steps). The page opens with default figures that give match found of yes, so you can see the scale before entering your own.

What does this Regular Expression Tester show?

It shows Match found, First match, Match starts at index, Match ends before index, Gave up (budget exhausted), Simulation steps used and Compiled instruction count, with the working and any warnings for your entries.

Can I check how the Regular Expression Tester result was calculated?

Yes. The “How this is worked out” section shows the calculation steps, and the sources section identifies the references used for the method.

Related calculators

View all related calculators12 more