Regex tester

The regex tester runs a regular expression on text, highlights the matches, shows the groups of each match, and replaces the matches with replacement text.
Input
Enter the expression without slashes at the start and end. The test uses JavaScript regular expression syntax, which may differ slightly from PHP, Python, or grep.
Flags
Up to 1,000,000 characters. Text in any language works.

The test runs in the browser and requires JavaScript. A fixed example is shown.

Matches: 2.
Matches
  1. Match 1
    Position
    12
    Length
    16
    Match
    info@example.com
    Group 1
    info
    Group 2
    example.com
    Named group user
    info
    Named group domain
    example.com
  2. Match 2
    Position
    30
    Length
    24
    Match
    support@mail.example.org
    Group 1
    support
    Group 2
    mail.example.org
    Named group user
    support
    Named group domain
    mail.example.org
Replace
Use $1 for a numbered group, $<name> for a named group, and $& for the whole match. Without the g flag only the first match is replaced.
Quick syntax reference
.
Any character except a line break. With the s flag, a line break too
\d
A digit, 0 to 9
\w
A Latin letter, digit, or underscore. Accented and non-Latin letters are not included
\s
A space, tab, or line break
^
Start of the text, or of a line with the m flag
$
End of the text, or of a line with the m flag
*
Zero or more times
+
One or more times
?
Zero times or once. After * or + the shortest match is taken
{n,m}
Between n and m times
[abc]
One of the characters in the brackets. A letter range: [a-z]
[^abc]
Any character not in the brackets
(...)
Numbered group
(?<name>...)
Named group
a|b
a or b
\b
Word boundary: between a \w character and another character

Everything runs in your browser; nothing is sent or stored.

  • Enter the expression without slashes at the start and end, and check the flags you need, such as g for all matches.
  • The result updates as you type, and the match list shows the position and the length of each match. Positions count from 0, in JavaScript UTF-16 units, and up to 1,000 matches are listed.
  • For an invalid expression, an error message appears, along with the engine message that describes the problem.
  • In the "Replace" section, enter the replacement text, and copy the text after the replacement with the "Copy" button.
  • The "Quick syntax reference" section lists the common symbols, with a short explanation of each one.

What is a regular expression?

A regular expression (regex for short) is a pattern that describes a sequence of characters. For example, the expression \d{4} matches four consecutive digits. Regular expressions are used to search, validate, and replace text, for example in website and app code, in form field validation, in redirect rules in the .htaccess file, and when searching log files with grep. The tester follows JavaScript syntax, so an expression written for another programming language may need minor changes.

Groups and replacement

Parentheses create a group, and groups are numbered by the order of their opening parentheses. You can name a group with the syntax (?<name>...), and parentheses with the syntax (?:...) group part of the expression without creating a numbered group. In the replacement text, $1 stands for the first group, $<name> for a named group, and $& for the whole match. For example, the expression (\d{4})-(\d{2})-(\d{2}) with the replacement text $2/$3/$1 turns the date 2026-11-24 into 11/24/2026. To output the $ character as is, without it being read as a group reference, write $$.

Greedy and lazy quantifiers

The quantifiers *, +, and {n,m} are greedy, meaning they match the longest possible sequence. That is why the expression <.+> on the text <b>bold</b> matches the whole text, from the opening tag to the closing tag. A question mark after the quantifier makes it lazy, and the expression <.+?> matches the shortest possible sequence, meaning each tag separately. A more precise alternative is a negated character class, such as <[^>]+>, which matches any character except >.

Common expressions

  • ^\d+$text that contains only digits. With the m flag, each line is checked separately.
  • ^[A-Za-z ]+$text that contains only English letters and spaces, in uppercase and lowercase.
  • \p{L}+a word in any language, including words with accented letters, such as café. The expression requires the u flag.
  • \b\d{1,3}(?:\.\d{1,3}){3}\ban IPv4 address. The expression also accepts numbers greater than 255, such as 999.999.999.999.
  • https?://[^\s]+a URL that starts with http:// or https://, up to the next space or line break.
  • [ \t]+$spaces and tabs at the end of a line, with the m flag. Replacing them with an empty replacement text removes them.
  • (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})a date in ISO 8601 format, with the named groups y, m, and d.

Regex tester FAQ

Why is an expression that works in PHP or Python shown as invalid?

The tester follows JavaScript syntax, which differs from the syntax of other languages. A named group is written as (?<name>...) and not as (?P<name>...), and the a++ and (?>...) syntaxes, as well as (?i) at the start of the expression, are not supported. In PHP, the expression is written between slashes, such as /abc/i. In the tester, enter only the content between the slashes and check the flags separately.

Why don't \w and \b find words with accented or non-Latin letters?

In JavaScript, \w includes only Latin letters, digits, and the underscore, and \b detects a word boundary based on \w only. That is why an expression such as \w+ does not match the whole word café or words in non-Latin scripts, and \b does not detect where those words start and end. For letters in any language, write \p{L} and check the u flag.

Why was the test stopped after one second?

The tester stops a test that takes more than one second, so that a slow expression does not make the page stop responding. The common cause is a quantifier nested inside another quantifier, as in the expression (a+)+$, which makes the engine try a huge number of combinations when there is no match. To fix it, remove the nesting, for example a+$ instead of (a+)+$, or write a more precise character class.

Why does the tester find only one match?

Without the g flag, the test stops at the first match, and the replacement also applies to the first match only. With the y flag, each match must start exactly where the previous match ended, and the first match must start at the beginning of the text. That is why, with the y flag, the test stops at the first character that does not match the expression, even when there are more matches later in the text.

Why is the position in the list different from the character count in the text?

The position is counted from 0, in JavaScript UTF-16 units. Most characters, such as letters, digits, and punctuation, take one unit, but emojis and rare characters take two units. Without the u flag, the dot matches a single unit only, meaning half an emoji, and with the u flag, the dot matches the whole character.

Can I test an expression on long text?

Yes. The tester accepts text of up to 1,000,000 characters. The list and the highlighting show up to the first 1,000 matches, and the total number of matches appears in the message above the match list. A match or group longer than 300 characters is shown in the list with its first 300 characters only.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement