DevSwitch.net

Resetting tool...

Back to Tools
</>

RegEx Tester

Test and debug regular expressions with instant visual feedback

Web Dev Tools

Tip: Enter your regex pattern and test string. Matches are highlighted in real-time. Click on common patterns for quick insertion.

Runs in your browser
/
Quick Patterns One-click insertion

Test String

Matches 0

Test a regex against your own text

Test a regex online against the text it really has to handle: type a pattern, paste the text, and every match lights up as you type. The counter shows how many matches there are, and the match details under the result list each one with its position and capture groups. Six flag buttons sit next to the pattern, and the quick patterns drop in a starting point for numbers, words, letters, email addresses, URLs and hex colors.

The regular expression runs on the JavaScript engine built into your browser, so it behaves exactly as it will in front-end code and Node.js. Your text stays on your device.

Read every match and capture group

The email pattern on the tool's sample line, with named groups:

pattern
(?<user>[\w.]+)@(?<domain>[\w.]+)
matches
1  9-29   [email protected]
   Group 1: john.doe     user: john.doe
   Group 2: example.com  domain: example.com
2  33-46  [email protected]
   Group 1: jane         user: jane
   Group 2: test.org     domain: test.org

Positions count characters from 0, start to end, as JavaScript's match.index does. A named group is listed twice, by number and by name, because JavaScript numbers it too: $1 in a replacement is Group 1. A group that took no part in a match shows as not matched instead of an empty string.

No pattern yet?

Paste a few strings it should match and the Regex Generator writes the pattern for you.

What each flag changes

The g flag is on when the page opens. Real results from the tool:

FlagWhat it doesExampleWithout / with
g global Finds every match, not only the first \d+ on a1 b22 c333 1 / 3
i ignore case Upper and lower case count as the same letter hello on Hello HELLO hello 1 / 3
m multiline ^ and $ match at the start and end of every line ^\w+ on two lines, alpha and beta 1 / 2
s dotAll . also matches a line break a.b on a, line break, b 0 / 1
u unicode Full Unicode: \p{Lu} property escapes and strict syntax \p{Lu} on Ärger 0 / 1
y sticky Each match has to start where the last one ended \d with g on 12a3 3 / 2

Debug a pattern that matches nothing, or too much

  • Problem

    ^\w+ only finds the first line

    Fix

    Without m, ^ and $ mean the start and end of the whole text. Turn on m to anchor each line.

  • Problem

    example.com matches exampleXcom

    Fix

    An unescaped dot matches any character. Write example\.com when you mean a real dot.

  • Problem

    ".*" grabs "a" and "b" in one match

    Fix

    * is greedy and runs to the last quote. The lazy ".*?" stops at the first one and finds "a" and "b" separately.

  • Problem

    The counter is higher than the highlights

    Fix

    A pattern that can match nothing, such as \d*, also matches the empty string between characters: on a1 it finds three matches, two of them empty. Use \d+ to require at least one character.

  • Problem

    The error ends in Invalid group

    Fix

    The message is the browser's own. (?i)abc causes this one in Chrome and Edge: inline flags at the start come from Python and PCRE, so use the i flag instead.

Patterns from Python, PHP or Java

Most syntax is shared. These are the differences that change results when you move a pattern into or out of JavaScript:

SyntaxJavaScript (this tester)Elsewhere
\A, \Z Not anchors. Without u, \A silently matches the letter A; with u it is an error Start and end of text in PCRE, Python and Java
(?i) at the start Error; use the i flag Inline flags in PCRE, Python and Java
(?P<name>…) Error; write (?<name>…) Python's syntax for named groups
(?<=…) lookbehind Any length, such as (?<=\$)\d+ Python's re accepts fixed-width lookbehind only
\d ASCII 0 to 9 only, even with u Python 3 also matches digits of other scripts, such as ٣

Lookahead and lookbehind themselves, with worked examples, are in the lookahead and lookbehind guide.

Regex tester questions

JavaScript's, also called ECMAScript regex: the engine in your browser, the same one Node.js uses. A pattern that works here works in JavaScript code with the same flags. For PHP, Python or Java, check the differences listed above.

Yes, it validates the pattern on every keystroke. The input turns red and your browser's own error message appears under it, such as Unterminated character class for a missing ], while your text stays visible without highlights.

Not here: the tester shows matches and groups, not replaced text. The groups in the match details are what a replacement refers to, so Group 1 is $1 and a group named year is $<year> in JavaScript's replace().

Add it to the address as a pattern parameter, URL-encoded: /en/regex-tester?pattern=%5Cd%2B opens the tester with \d+ filled in. Flags and text are not part of the link.

Nested quantifiers such as (a+)+$ make the engine try an exploding number of combinations on text that almost matches. This is called catastrophic backtracking, and it freezes real code the same way. Make the inner part match one way only, for example a+$.

No. Matching runs in your browser, so logs and private data you paste stay on your device.