Skip to content

Regex Tester - Test Regular Expressions Online

//

Test a regex against real text

Type a pattern between the slashes, set flags, and paste the text you want to search. Every match is highlighted in the text, and the list below shows each match with its index, length and capture groups. Results update as you type.

The tester uses your browser's JavaScript RegExp, so the results are what String.match, matchAll and replace will see in your code. Up to 10,000 matches are listed.

Example

Pattern ^(\w+)=(.*)$ with flags gm, against:

HOST=localhost
PORT=5432
# comment
DEBUG=

gives three matches. PORT=5432 has $1 = PORT and $2 = 5432. DEBUG= matches with an empty $2, and the comment line is skipped because # is not a word character. Remove the m flag and nothing matches, because ^ and $ then refer to the whole string.

Gotchas that differ from other languages

  • . does not match a newline unless you add the s flag. [\s\S] is the old workaround.
  • \d and \w are ASCII only, even with u. Use \p{L} with the u flag to match letters such as é or ß.
  • In a JavaScript string literal you need to double every backslash: the pattern \d+ is written new RegExp("\\d+"). In this tester, type the pattern as you would between slashes.
  • A regex with the g flag keeps its position in lastIndex, so calling .test() twice on the same string can return true and then false.

Common patterns

  • ISO date: \d{4}-\d{2}-\d{2} (checks the shape, not that the date exists).
  • Loose email check: ^[^\s@]+@[^\s@]+\.[^\s@]+$. A full RFC 5322 regex is not worth it; send a confirmation email.
  • IPv4 address: \b(?:\d{1,3}\.){3}\d{1,3}\b (also accepts 999.999.999.999).
  • Trailing whitespace: [ \t]+$ with the m flag.

Related Tools

Frequently Asked Questions

Which regex flavour does this use?
JavaScript (ECMAScript), using your browser's own RegExp engine. A pattern that works here works the same in browser code and Node.js. Patterns copied from PHP, Perl or Python may need rewriting. Possessive quantifiers (a++) and atomic groups (?>...) are syntax errors in JavaScript. Worse, \A and \Z are not errors without the u flag: they quietly match a literal A or Z. Use ^ and $ instead.
Which flags can I use?
The checkboxes cover g (find every match, not just the first), i (ignore case) and m (^ and $ match at each line break). You can type any other flag into the flags box: s lets . match newlines, u turns on full Unicode mode and \p{...} property escapes, y is sticky, and d adds match indices.
Why does my pattern only find one match?
The g flag is off. Without it, JavaScript stops at the first match, and so does this tester. Tick Global to see them all.
How are capture groups shown?
Each match lists its groups as $1, $2 and so on, the same numbers you would use in a replace string. (\d{4})-(\d{2})-(\d{2}) against 2024-01-15 gives $1 = 2024, $2 = 01, $3 = 15. A group that did not take part in the match shows as undefined. Named groups such as (?<year>\d{4}) work but are listed by number.
What does "Pattern took too long" mean?
Matching runs in a background worker and is stopped after 1.5 seconds. That almost always means catastrophic backtracking: a quantifier inside another quantifier, such as (a+)+ or (\w*)*, failing against a long string. The engine tries every way of splitting the input between the groups. Remove the nesting or make the alternatives mutually exclusive.