Use this free regex tester to try out regular expressions against your own text. Type a pattern, choose your flags, and paste a test string. Matches are highlighted as you type, and the tool lists every match with its position and capture groups. You can also add a replacement to preview a find and replace. Everything runs in your browser, so your pattern and text are never uploaded.

A regular expression is a small program for finding patterns in text. Testing it on real examples before you use it saves bugs, broken validation, and bad search and replace results.

How to use the regex tester

  • Enter a pattern: type it without the surrounding slashes, for example \d{3}-\d{4}.
  • Choose flags: toggle g, i, m, s, and u. The g flag is on by default so every match is found.
  • Add test text: paste sample text. Matches are highlighted and listed with their index and groups.
  • Preview a replacement: optionally enter a replacement string to see the text after find and replace.
  • Copy the result: copy the list of matches, or copy the regex as /pattern/flags for your code.

Regex flags

FlagSyntaxWhat it does
GlobalgFinds every match instead of stopping at the first one
Ignore caseiTreats uppercase and lowercase letters as the same
MultilinemMakes ^ and $ match at the start and end of each line
Dot allsLets the dot match newline characters too
UnicodeuHandles full Unicode characters and stricter escape rules

Common regex building blocks

TokenSyntaxMeaning
Any character.Matches any single character except a newline
Digit\dMatches 0 to 9. Use \D for anything else
Word character\wMatches letters, digits, and underscore
Whitespace\sMatches spaces, tabs, and line breaks
Word boundary\bMatches the edge between a word and a non-word character
Character set[abc]Matches one of the listed characters. [^abc] excludes them
Group(abc)Captures the match so you can reuse it as $1, $2, and so on
Alternationa|bMatches either a or b
Quantifiers* + ? {n,m}Repeat the previous item zero or more, one or more, zero or one, or n to m times
Anchors^ $Match the start and the end of the text (or line with the m flag)

How the tester works

The tool builds a JavaScript RegExp object from your pattern and flags, then runs it against your text in the browser. Each match is shown with its starting index, and capture groups, including named groups, are listed under it. The tool stops after 1,000 matches to keep the page responsive. If the pattern is invalid, the error message from the browser is shown so you can fix it. Syntax differs slightly between languages, so features such as lookbehind, possessive quantifiers, and named group syntax may behave differently in PHP, Python, or other engines.

Tips for better patterns

  • Start small: build the pattern one piece at a time and check the highlights after each change.
  • Escape special characters: use a backslash before . * + ? ( ) [ ] { } | ^ $ \ when you mean the literal character.
  • Prefer specific classes: [A-Za-z]+ is safer than .+ because it cannot run past the part you want.
  • Watch for greedy matches: .* takes as much as it can. Use .*? for the shortest match.
  • Avoid nested repeats: patterns like (a+)+ can run very slowly on some inputs.
  • Test edge cases: include empty lines, extra spaces, and text that should not match.
Whether you are validating a form, cleaning a data file, or searching logs, a regex you have tested on real examples is one you can trust.

Worked examples

Find email addresses

Enter \b[\w.+-]+@[\w-]+\.[\w.]+\b with the g and i flags and paste a paragraph with a few addresses. Each address is highlighted. Add the replacement [email] to see them masked.

Capture groups

Enter (\d{4})-(\d{2})-(\d{2}) and the text 2026-11-18. The match list shows groups 1, 2, and 3 as the year, month, and day. Use the replacement $3/$2/$1 to turn the date into 18/11/2026.

Match line starts

Enter ^\w+ with the g and m flags on a multi-line text. Each line’s first word is highlighted. Without the m flag, only the start of the whole text can match.

Frequently asked questions

Is this tool free to use?

Yes. You can test as many patterns as you like without creating an account.

Does the tool store my pattern or text?

No. Testing happens in your browser. Nothing you type is saved on this page or sent to a server, and clearing the form removes it from the screen.

Which regex flavor does it use?

JavaScript (ECMAScript). Most basic syntax is shared with PHP, Python, and other languages, but advanced features can differ, so test in your target language before you ship.

Why do I only see one match?

The g flag is off. Turn it on to find every match in the text.

Why does my pattern show an error?

The pattern is not valid in JavaScript. Common causes are an unclosed group or bracket, a quantifier with nothing before it, or an invalid escape when the u flag is on.

Why does the tool stop at 1,000 matches?

Large result sets can slow the page. The limit keeps the tester responsive. Narrow the pattern or shorten the text to see the rest.

Share this article