Regex Tester – Test Regular Expressions Online
Write a regular expression, paste some text and see every match instantly, with its position in the text, numbered capture groups and named groups. Try different flags, or enter a replacement to see the text after a find-and-replace. Uses JavaScript regex syntax.
How to use the regex tester
- Type your regular expression (without the surrounding slashes).
- Enter the flags, such as g, i or m.
- Paste your test text.
- Optionally enter a replacement to preview a find-and-replace.
The output lists each match with its position, and the values of numbered and named groups. The status line shows how many matches were found.
Regex basics
| Pattern | Matches |
|---|---|
\d | a digit |
\w | a letter, digit or underscore |
\s | whitespace |
. | any character except a new line |
[abc] | a, b or c |
[^abc] | anything except a, b or c |
^ and $ | start and end of the text (or line with m) |
* + ? | 0 or more, 1 or more, 0 or 1 |
{2,4} | between 2 and 4 times |
(…) | a capture group |
(?<name>…) | a named group |
a|b | a or b |
Worked example
Pattern (?<year>\d{4})-(\d{2})-(\d{2}) with the g flag, on the sample text, finds two dates: 2026-11-08 and 2026-11-09. For the first, the named group year is 2026 and the numbered groups are 2026, 11 and 08.
Useful patterns
- Email address (simple):
[\w.+-]+@[\w-]+\.[\w.]+ - Whole word:
\bword\b - Trailing spaces at line ends:
[ \t]+$with the m flag - Numbers with decimals:
-?\d+(\.\d+)? - Hex colour:
#[0-9a-fA-F]{6}\b
Validating real-world data such as emails and URLs fully with regex is hard; these simple patterns catch most cases.
Regex in other languages
The core syntax is the same almost everywhere, but details differ. Python uses (?P<name>…) for named groups, PHP and Perl wrap patterns in delimiters, and Java needs every backslash doubled inside string literals. Some engines support features JavaScript lacks, such as possessive quantifiers and atomic groups. When moving a pattern between languages, test it again in the target language’s own tools.
Escaping in code
In many languages a regex written as a string needs double backslashes: the pattern \d becomes "\\d" in a Java or C# string. JavaScript regex literals between slashes, such as /\d+/, avoid this. When a pattern works here but not in your code, escaping is the first thing to check.
Tips
- Start small and build the pattern up piece by piece.
- Use named groups to make complex patterns readable.
- Beware of catastrophic backtracking — nested quantifiers such as
(a+)+can be extremely slow on long text. - Anchor your pattern with ^ and $ when validating a whole value.
For simple replacements without regex, use the find and replace tool. Format data first with the JSON formatter, or escape HTML with the HTML entity encoder.
Frequently asked questions
Which regex syntax does the tester use?
JavaScript (ECMAScript) regular expressions, as used in browsers and Node.js. Most syntax is shared with Python, Java, PHP and .NET, but some features, such as lookbehind support or possessive quantifiers, differ between languages.
What do the flags mean?
g finds all matches instead of the first; i ignores case; m makes ^ and $ match at line breaks; s lets . match new lines; u enables full Unicode; y matches only at the current position; d records match positions.
How do I use capture groups in a replacement?
Use $1, $2 and so on for numbered groups, or $<name> for named groups. With the pattern (\d{4})-(\d{2})-(\d{2}) and replacement $3/$2/$1, 2026-11-08 becomes 08/11/2026.
How do I match a literal dot or bracket?
Escape it with a backslash: \. matches a full stop and \( an opening bracket. Characters with special meaning are . * + ? ^ $ ( ) [ ] { } | \ and /.
Why does my pattern match too much?
Quantifiers like * and + are greedy — they match as much as possible. Add ? to make them lazy: <.+?> matches one HTML tag instead of everything from the first < to the last >.
Is my text sent anywhere?
No. Matching runs in your browser.
Related tools
Find and Replace
Replace words in text, with case, whole-word and regex options.JSON Formatter
Pretty-print, validate and minify JSON with clear error positions.Text Compare
Highlight the differences between two texts, by word or by line.URL Encoder / Decoder
Percent-encode or decode URLs, with a query-parameter table.HTML Entity Encoder
Escape and unescape HTML entities like & and é.
Last updated: