Regex Problems

How to Test a Regular Expression Step by Step

Testing a regular expression means running it against both text it should match and text it should reject. A pattern that only works on your first example is not ready. Test the edge cases before it goes into code.

Last updated: 2 November 2026

Open Regex Tester →

Step-by-step

  1. Write the pattern and decide which flags you need.
  2. Paste sample text that includes values that should match and values that should not.
  3. Run the test and check every line, not only the first match.
  4. Add anchors ^ and $ if the whole value must match, not just a part of it.
  5. Try edge cases: empty text, very long text, unusual characters and the examples that should fail.
  6. Copy the pattern into your code and test it there, since regex engines differ slightly between languages.

Flags that change the result

The i flag ignores case. The m flag makes ^ and $ match at the start and end of each line. The s flag lets the dot match a new line. The g flag finds every match rather than the first. Check which flags your code will actually use.

Greedy and lazy matching

By default quantifiers such as * and + match as much as possible. In the text <b>one</b><b>two</b>, the pattern <b>.*</b> matches the whole string, while <b>.*?</b> matches each tag separately. Use the lazy form when you want the shortest match.

Patterns that can be slow

Nested quantifiers such as (a+)+ can take a very long time on input that almost matches, because the engine tries many combinations. Keep patterns simple, avoid overlapping alternatives, and limit the length of input you test in production.

Engines differ

Features such as lookbehind, named groups and Unicode handling vary between JavaScript, Python, PHP and others. The Regex Tester uses the JavaScript engine, so confirm the result in your own language.

USE THE TOOL

Finish the task with DevUtilityKits

Use the relevant online utility, check the result, and continue with your development workflow.

Open Regex Tester →Open Regex Generator →
FAQ

Frequently asked questions

How do I test a regex online?

Enter the pattern and flags, paste sample text and check which parts match. Include examples that should fail as well as ones that should match.

Why does my regex match only part of the text?

It is probably missing anchors. Add ^ at the start and $ at the end to require the whole value to match.

What is the difference between greedy and lazy?

Greedy quantifiers match as much as possible. Adding ? makes them lazy, matching as little as possible.

Will my pattern work in other languages?

Often, but not always. Test it in the language you will use, because syntax and features differ.