Regex Tester

Enter a regular expression pattern and a test string to highlight matches and list capture group values. Supports the g/i/m/s/u flags using JavaScript's native RegExp.

Common regex patterns

Use case Pattern Description
Email address ^[\w.+-]+@[\w-]+\.[\w.-]+$ Matches a simplified email address format with a username and domain separated by @ (not fully RFC-compliant).
US phone number ^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ Matches common US phone number formats, with or without parentheses and separators (e.g. (555) 123-4567, 555-123-4567).
URL https?:\/\/[\w.-]+(?:\/[\w\-./?%&=]*)? Extracts URL strings starting with http:// or https://, including any path and query parameters.
US ZIP code ^\d{5}(-\d{4})?$ Matches a 5-digit ZIP code, optionally followed by the 4-digit ZIP+4 extension.
Hex color code ^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$ Matches CSS hex colors in the full #RRGGBB form or the shorthand #RGB form.
Digits only ^[0-9]+$ Checks whether the entire string consists only of digits (0-9).

What is a regex tester?

A regular expression (regex) is a compact mini-language for searching, extracting, and validating patterns within text. Tasks like "check whether this looks like a valid email address" or "pull out only the IP addresses from a log file" can be expressed in a single pattern. The trade-off is that the syntax is dense and symbol-heavy, so it is genuinely hard to tell just by reading a pattern whether it behaves the way you intended.

This tool evaluates the regex pattern and test string you type against JavaScript's native RegExp engine in real time and highlights every match in yellow directly in the text. It also lists each capture group's value, the total match count, and any syntax error, so you can iterate on a pattern — tweak it, see what changed, tweak again — entirely inside the browser without writing any code or spinning up a runtime.

Because everything runs client-side using the exact same engine that powers regular expressions in your browser's JavaScript, form validators, and Node.js backends, what you see here is a faithful preview of how the pattern will behave once it ships to production. It is a fast way to sanity-check a tricky pattern before pasting it into real code.

How to use the regex tester

  1. Type your regex pattern Enter the pattern you want to test in the field at the top. The surrounding slashes / / are added automatically, so just type the pattern body itself.
  2. Choose the flags you need Toggle the g, i, m, s, and u checkboxes as needed. Leave the g flag on if you want to see every match instead of only the first one.
  3. Paste in a test string Paste or type the text you want to match against into the text area below. Multi-line text is fully supported.
  4. Review the highlights and the table The result recalculates automatically as you type. Matched substrings are highlighted in yellow, and the table below lists the full match and every capture group value for each occurrence.
  5. Refine the pattern If the match count or matched range is not what you expected, adjust the pattern or flags directly and watch how the highlighted result changes.

Tips for getting more out of it

  • The /flags shown next to the pattern field lets you see at a glance which flag combination is currently active.
  • Only the parts wrapped in () count as capture groups. Use a non-capturing group (?:...) if you just need to group a condition without cluttering up the groups list.
  • Without the g flag, only the first match is found. Turn on the g flag if you want to count every occurrence in the text.
  • The "Insert sample" button loads an email-extraction example, which is a good starting point for understanding how capture groups behave.
  • All matching happens entirely inside your browser — the pattern and test string you type are never sent to any server.

Common use cases for a regex tester

Designing form validation rules

Verify a regex you plan to use for input validation before wiring it into a form — confirm that expected inputs (with or without hyphens, accented characters, etc.) pass and that malformed input is correctly rejected.

Extracting fields from server logs

Paste a real snippet of an access log or error log and build a pattern that pulls out just the fields you need, such as IP addresses, timestamps, or HTTP status codes.

Cleaning up CSV or free-text data

Before normalizing inconsistently formatted phone numbers or dates, use the tool to classify which rows match a given pattern and which do not.

Verifying behavior during code review

When a colleague's regex is hard to read at a glance, paste in real sample values and visualize exactly what it matches to resolve the question on the spot.

Checking for side effects when editing a pattern

When modifying an existing regex, compare the highlighted matches before and after your edit against the same test string to confirm the behavior did not change unexpectedly.

Regex glossary

Capture group
A portion of a pattern wrapped in (). Use it when you need to extract a sub-part of the overall match rather than the whole matched string. This tool's result table lists each group's value under Group 1, Group 2, and so on.
Non-capturing group
A group written as (?:...). Use it when you only need parentheses to group a condition — it keeps the numbering of your real capture groups clean and the result list easier to read.
Backreference
A way to reuse the text matched by an earlier capture group later in the same pattern. Numbered groups are referenced with \1, and named groups with \k<name>. Commonly used to detect repeated words or duplicated tokens.
Lazy (non-greedy) matching
Adding ? right after a quantifier (such as * or +) makes it match as little text as possible. By default (greedy matching), quantifiers try to match as much as possible, so the distinction matters when extracting something narrow, like the contents of a single HTML tag.
Lookahead and lookbehind
Collectively refers to (?=...) (positive lookahead), (?!...) (negative lookahead), (?<=...) (positive lookbehind), and (?<!...) (negative lookbehind). They let you require that certain text exists nearby without including that text in the match itself.
Character class
A set of characters enclosed in square brackets, such as [abc] or [a-z0-9], that matches any single character within it. Placing ^ right after the opening bracket, as in [^abc], negates it to mean "any character except these."
Anchor
A token that matches a position rather than an actual character. ^ anchors to the start of the string (or of each line with the m flag), $ to the end, and \b to a word boundary.
Flag
An option that changes how the whole pattern is interpreted. This tool supports the five JavaScript flags: g (find all matches), i (ignore case), m (multiline), s (let dot match newlines), and u (proper Unicode handling).

Frequently Asked Questions

Without the g (global) flag, the regex only matches the first occurrence in the string, and any later occurrences are ignored. Turn on the g flag if you want to find every match.

The basic syntax ([abc], \d, +, *, etc.) is largely shared, but named group syntax, lookahead/lookbehind support, and available flags differ in subtle ways between languages. This tool follows JavaScript's RegExp specification, so it doesn't guarantee identical behavior elsewhere.

No. All processing happens entirely in your browser's JavaScript, and nothing you type is sent to or stored on toolbase.cc's servers.

This appears whenever JavaScript's RegExp constructor detects a syntax error — for example, an unclosed parenthesis, a quantifier (*, +, ?) with nothing before it, or an invalid character class. The error message usually gives a hint, so check your parenthesis balance and escaping of special characters (like \. or \().
Tool-kun

Side Note — What happens inside a regex engine

Regular expressions trace back to the theory of "regular languages" proposed by mathematician Stephen Kleene in the 1950s. Early Unix tools such as the ed text editor and the grep command (short for "globally search a Regular Expression and Print") adopted this theory as a practical implementation, which is how the term spread rapidly through text-processing tools. It is telling that the name "grep" itself derives from a regex operation.

JavaScript's RegExp engine matches patterns internally using a strategy called backtracking: it tries each element of the pattern in order and, if a later part fails, steps back and tries an alternative. This flexibility comes with a downside — patterns like (a+)+b combined with a long non-matching string can cause the number of attempts to grow exponentially, a phenomenon known as "catastrophic backtracking" that can freeze a browser or server. Always test complex patterns against a variety of inputs before shipping them to production.

A regex object with the global (g) flag keeps an internal cursor called lastIndex, and each call to exec() resumes searching from that position. Reusing the same regex object across unrelated searches can leave this cursor in an unexpected state, so this tool creates a brand-new RegExp instance every time to avoid carrying over any stale state.

Named capture groups ((?<name>...)) were added in ECMAScript 2018 and are a relatively recent feature. Referring to a group by name instead of by number makes complex patterns far more readable — especially useful in situations like date parsing, where knowing what each group represents really matters.