Skip to content

Regex Tester

Test and debug your JavaScript regular expressions in real-time.

/ /

Matches

0 matches
Advertisement

How to use the regex tester

  1. Enter your pattern without slashes, e.g. \b\d{3}-\d{4}\b.
  2. Enter flags such as g (find all matches), i (ignore case) or m (multi-line).
  3. Paste your test text. Matches are highlighted live and the match count updates as you type.

The tester uses your browser's JavaScript regex engine, so results match what RegExp does in Node.js and the browser. Other engines (PCRE, Python, Java) differ in some advanced features.

Regex cheat sheet

TokenMeaning
.Any character except a newline
\d / \w / \sDigit / word character (letter, digit, underscore) / whitespace
\D / \W / \SThe opposite of each of the above
[abc] / [^abc]One of a, b or c / any character except those
^ / $Start / end of the string (or of a line with the m flag)
\bWord boundary
* / + / ?0 or more / 1 or more / 0 or 1
{n,m}Between n and m repetitions
*?, +?Lazy (as few as possible) versions
(…) / (?:…)Capturing group / non-capturing group
a|ba or b
(?=…) / (?!…)Lookahead / negative lookahead

Handy patterns to start from

  • Simple email check: ^[^\s@]+@[^\s@]+\.[^\s@]+$
  • Indian 10-digit mobile number: ^[6-9]\d{9}$
  • Date in YYYY-MM-DD form: ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
  • Hex colour: ^#([0-9a-fA-F]{3}){1,2}$
  • Password with at least one digit, one upper and one lower case letter, 12+ characters: ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{12,}$

Common mistakes

  • Forgetting the g flag, so only the first match is found.
  • Not escaping special characters: to match a literal dot, use \..
  • Greedy matching: <.*> matches from the first < to the last >; use <.*?>.
  • Catastrophic backtracking: nested quantifiers like (a+)+ can freeze on long input. Keep patterns specific.