FA Dev Tools

Regex

Test a JavaScript regular expression against your own text. Matches are highlighted as you type, with every capture group, a replace preview, a list of the matches and a split. Nothing leaves your browser.

//g

Type a pattern to start.

/(?:)/g
Flags

Common patterns

text.split(regex) — the text between matches. Anything a capture group caught is kept as its own piece, as the real call does; flags such as g make no difference here.

Pieces

The pieces appear here, one per line.
Instructions

A tester for JavaScript regular expressions — the same engine your browser and Node use. Everything runs in your browser; the pattern and text are kept in this browser's local storage so they survive a reload.

  1. Type a pattern between the slashes. Leave out the slashes and flags — pick flags with the toggles below (g is on by default).
  2. Paste the text to test into Test text. Matches are highlighted as you type.
  3. Matches lists each match with its position and capture groups. Replace previews text.replace(), List puts every match (or one group) on its own line, and Split shows text.split().
  4. Copy the result, or copy the pattern as a /…/flags literal ready to paste into code.

Tips

  • This is JavaScript's dialect. PCRE-only syntax such as possessive quantifiers (a++), atomic groups (?>…) and inline flags (?i) is a syntax error here, and Python's (?P<name>…) is written (?<name>…).
  • Backslashes are typed once: write \d, not the \\d you would need inside a string passed to new RegExp().
  • Without g only the first match is found. Without m, ^ and $ match only at the very start and end of the whole text, not at each line.
  • A pattern that runs longer than a second is stopped, so something like (a+)+$ cannot freeze the page. That usually means nested quantifiers are backtracking; make the inner part more specific.
  • A pattern that can match nothing (a*, \b) shows empty matches as thin carets in the highlighted text.
  • Hit Example, then click a Common patterns chip, Load example, or one of the Replace, List and Split tabs to see it run on sample text.

Cheat sheet

.Any character except a line break (any at all with s)
\d \w \sDigit, word character [A-Za-z0-9_], whitespace
\D \W \SThe opposite of each
\b \BWord boundary, not a word boundary
^ $Start / end of the text (of each line with m)
[abc] [^abc] [a-z]One of, none of, a range
* + ?0 or more, 1 or more, 0 or 1
{3} {2,} {2,5}Exactly 3, 2 or more, 2 to 5
*? +? ??Lazy — as few as possible
(…)Capture group, $1 in a replacement
(?<name>…)Named group, $<name> in a replacement
(?:…)Group without capturing
\1 \k<name>Backreference — the same text again
a|bEither
(?=…) (?!…)Followed by, not followed by
(?<=…) (?<!…)Preceded by, not preceded by
\p{L} \p{Lu}Unicode letter, upper-case letter (needs u or v)