📚 Developer · Guide

How to Test Regular Expressions Online: A Practical Regex Guide

Test regular expressions against real text and see every match and capture group. Learn the regex building blocks, useful patterns for emails and phone numbers, and how to avoid common traps.

By RexBD Team 24 Nov 2026 7 min read 1,528 words
How to Test Regular Expressions Online: A Practical Regex Guide

Regular expressions, usually called regex, are a compact language for describing patterns in text. With one line you can find every email address in a document, check that a phone number has the right format, pull dates out of a log file or replace every double space in a manuscript. They are built into almost every programming language, text editor, spreadsheet tool and database.

They are also famously easy to get wrong. A pattern that looks correct can match too much, too little or nothing at all. The fastest way to learn and debug regex is to test it against real text and see what happens. This guide shows how to do that with the free Regex Tester on RexBD.

How to use the Regex Tester

Step 1: Enter your pattern

Open the Regex Tester and type your regular expression into the pattern field.

Step 2: Set flags

Flags change how the pattern behaves. The most common are:

  • g (global): find all matches, not just the first.
  • i (ignore case): treat upper and lower case as the same.
  • m (multiline): make ^ and $ match the start and end of each line, not just the whole text.
  • s (dotall): let . match line breaks too.
  • u (unicode): proper Unicode handling, important for Bangla and emoji.

Step 3: Paste test text

Paste sample text that should match, and text that should not. Good test text includes tricky edge cases.

Step 4: Review matches and groups

The tool highlights every match and lists the capture groups for each one. Adjust the pattern until the results are exactly right.

The tester uses your browser's JavaScript regex engine and runs entirely on your device, so log files and customer data stay private.

🧪 Free tool · no sign-upTry the Regex TesterTest regular expressions against text and see every match and group. Open tool →

The building blocks of regex

You do not need to memorise everything. These pieces cover the large majority of real-world patterns.

Literal characters

Most characters match themselves. The pattern cat matches the text "cat".

Special characters that need escaping

These characters have special meanings: . ^ $ * + ? ( ) [ ] { } | \. To match one literally, put a backslash before it. For example, \. matches a real full stop, and \$ matches a dollar sign.

Character classes

Pattern Matches
. Any character except a line break
\d A digit (0–9)
\w A word character (letter, digit or underscore)
\s Whitespace (space, tab, line break)
\D, \W, \S The opposite of the above
[abc] One of a, b or c
[a-z] Any lowercase English letter
[^0-9] Anything that is not a digit

Quantifiers

Pattern Meaning
* Zero or more
+ One or more
? Zero or one (optional)
{3} Exactly 3
{2,5} Between 2 and 5
{2,} 2 or more

Anchors

  • ^ matches the start of the text (or line, with the m flag).
  • $ matches the end.
  • \b matches a word boundary, so \bcat\b matches "cat" but not "category".

Groups and alternatives

  • (abc) groups part of a pattern and captures what it matched.
  • (?:abc) groups without capturing.
  • a|b matches a or b.
  • (?<year>\d{4}) is a named group, which makes results easier to read.

Useful patterns you can adapt

Test each of these in the tool with your own data. Real data is always messier than examples.

Bangladeshi mobile number (local format, 11 digits starting with 01):

^01[3-9]\d{8}$

The same number with an optional +880 or 880 prefix:

^(?:\+?880)?01[3-9]\d{8}$

A simple email check (good enough for most forms):

^[^\s@]+@[^\s@]+\.[^\s@]+$

A date in YYYY-MM-DD format:

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$

A hex colour code:

^#(?:[0-9a-fA-F]{3}){1,2}$

Two or more spaces (for cleaning text):

{2,}

A URL slug (lowercase letters, digits and hyphens):

^[a-z0-9]+(?:-[a-z0-9]+)*$

A note about email regex

Perfectly validating email addresses with regex is famously difficult, because the official rules allow many unusual formats. A simple pattern like the one above catches typos such as missing @ signs, which is what forms usually need. The only real proof that an address works is sending an email to it.

Ad Kothay

A worked example: extracting order numbers from messages

Suppose a shop receives customer messages like these:

Hi, my order ORD-20431 hasn't arrived.
Can you check ord-20577 and ORD-20612 please?
Refund for order number 20698?

You want every order number in the format "ORD-" followed by five digits. A first attempt, ORD-\d{5}, finds only "ORD-20431" and "ORD-20612", missing the lowercase one. Adding the i flag fixes that and finds three matches.

Then you want just the digits. You add a capture group: ORD-(\d{5}) with flags gi. The tool shows each match and group 1 holds "20431", "20577" and "20612". The fourth message has no "ORD-" prefix, so it is not matched. Whether that is correct depends on your needs, and seeing it in the tester makes you decide consciously instead of discovering it later in production.

For quick extraction jobs like pulling all emails or phone numbers from text, RexBD also has ready-made tools: the Email Extractor, Phone Number Extractor and URL Extractor.

Greedy versus lazy matching

By default, quantifiers are greedy: they match as much as possible. Consider the text <b>one</b> and <b>two</b> and the pattern <b>.*</b>. You might expect two matches, but the greedy .* runs all the way to the last </b>, producing one long match.

Add ? to make a quantifier lazy: <b>.*?</b> matches as little as possible, giving two separate matches. This difference causes a large share of regex surprises, and it is obvious the moment you test it.

How to build a pattern step by step

Beginners often try to write a whole regex in one go and then cannot tell which part is wrong. A better method is to build it gradually while watching the matches in the tester:

  1. Start with a literal piece you know appears in every match, such as "ORD-" or "@".
  2. Add one element at a time, for example \d for a digit, then turn it into \d{5} for five digits.
  3. Check the matches after every change. If the match count suddenly jumps or drops to zero, the last change is the cause.
  4. Add anchors last if the pattern is for validation, so you can see partial matches while building.
  5. Paste in negative examples, text that must not match, and make sure it stays unhighlighted.
  6. Add capture groups around the parts you want to extract.
  7. Save the final pattern with a comment in your code explaining what it matches, with one example. Future you will be grateful.

Working this way turns regex from guesswork into a quick, visible process. It also helps you learn, because you see exactly what each symbol does.

Regex in everyday tools

You do not need to be a programmer to benefit from regex. Many everyday tools support it:

  • Text editors such as VS Code, Notepad++ and Sublime Text have regex find-and-replace.
  • Google Sheets has REGEXMATCH, REGEXEXTRACT and REGEXREPLACE functions.
  • Google Analytics and many reporting tools accept regex filters, for example to group several page addresses together.
  • Databases such as MySQL and PostgreSQL support regex in queries.

Testing a pattern in the Regex Tester before using it in these tools avoids mistakes in reports and data cleaning.

Common regex mistakes

  • Forgetting to escape dots. example.com also matches "exampleXcom". Use example\.com.
  • Missing anchors in validation. \d{11} finds 11 digits anywhere, even inside a longer number. For validation, use ^\d{11}$.
  • Forgetting the global flag when you want all matches.
  • Overly complex patterns. If a regex becomes unreadable, split the job into steps or use code.
  • Catastrophic backtracking. Nested quantifiers such as (a+)+$ can take an extremely long time on certain inputs. Avoid nesting quantifiers on overlapping patterns, especially for user input on servers.
  • Assuming all engines are the same. JavaScript, Python, PHP and others differ slightly, especially in lookbehind support and Unicode handling. Test in the engine you will actually use.

Regex and Bangla text

\w and [a-z] only cover English letters, digits and underscores in JavaScript. For Bangla, use the Unicode range [ঀ-৿] or, with the u flag, Unicode property escapes such as \p{Script=Bengali}. For example, [ঀ-৿]+ with the u flag matches runs of Bangla characters.

Our regex tips and mistakes article covers more advanced techniques such as lookahead and named groups.

Frequently asked questions

Which regex flavour does the tester use?

It uses your browser's JavaScript (ECMAScript) regex engine. Most patterns work the same in other languages, but check advanced features in your target language.

Why does my pattern only find one match?

Add the g (global) flag to find all matches.

How do I match a literal dot or bracket?

Escape it with a backslash, for example \. or \[.

Can I test patterns for Bangla text?

Yes. Use the u flag and Unicode ranges such as [ঀ-৿].

Is my test text uploaded?

No. Everything runs in your browser.

Is the Regex Tester free?

Yes. It is free and needs no account.

Found this useful?Share it with a friend or colleague who needs it.

Keep reading

More developer articles
321 free tools, one placeSEO, text, images, code, money, units and design. Private, fast and almost all in your browser.
Ad Kothay