calculate.sh DE

This tool runs in your browser using JavaScript. If it does not appear, please enable JavaScript or reload the page. The description below explains how it works.

Regex Tester

A regular expression (regex) is a compact pattern language for matching text. This tool lets you write a pattern, type some test text, and watch the matches light up as you type - with capture groups listed, flags you can toggle, and a replacement mode for testing substitutions. It uses the native JavaScript RegExp engine, so whatever you see here is exactly what new RegExp(pattern, flags) will do in your own code.

How to use

  1. Type a pattern into the field between the slashes. Adjacent to it, the six flag buttons g i m s u y can be toggled on and off.
  2. Type or paste test text in the left pane. Every match is highlighted in the right pane as you type, and adjacent matches alternate colours so you can see where one ends and the next begins.
  3. Read the match list below the preview: each entry shows the match number, its character position (pos start–end), the matched text, and any capture groups.
  4. Switch to Replace to test a substitution. You get a replacement field (using $1, $&, and $<name> references) and a live result pane.

The flags

  • g (global) - find every match instead of only the first. Without it, only the first match is highlighted and only the first is replaced.
  • i (ignore case) - abc also matches ABC and Abc.
  • m (multiline) - ^ and $ additionally match at the start and end of each line.
  • s (dotAll) - . also matches newline characters.
  • u (unicode) - enables full Unicode mode; required for correct handling of astral characters (emoji and other code points beyond U+FFFF) and \p{…} property escapes.
  • y (sticky) - the match must begin exactly at lastIndex; useful for tokenizers that read a stream piece by piece.

Capture groups and replacement

Parentheses create capture groups, numbered from 1. Named groups ((?<year>\d{4})) expose their value by name. In Replace mode the replacement string can reference them:

  • $1, $2 … insert the numbered group,
  • $<name> inserts a named group,
  • $& inserts the whole match,
  • $$ inserts a literal dollar sign.

For example, the pattern (\d{4})-(\d{2})-(\d{2}) with the replacement $3.$2.$1 turns 2024-01-15 into 15.01.2024. If the g flag is off, only the first match is replaced; turn it on to replace every occurrence.

Notes and examples

  • \b\w{5}\b highlights every five-letter word: in "The quick brown fox", it marks quick and brown (\b\w{4}\b finds nothing there - no word in that sentence has exactly four letters).
  • \d{3,} finds runs of digits at least three long, so 12 is skipped while 1234 matches.
  • A regex that matches an empty string - for example a* or (?:) - would match at every position. The engine has to be advanced manually to avoid an infinite loop, and this tool does that correctly, so those patterns stay responsive. Only the first 2,000 matches are collected to keep the page fast on huge inputs.
  • Invalid patterns are reported with the browser's own SyntaxError message (for example "Unterminated group"), directly under the toolbar, rather than failing silently.

Limitations

  • This is JavaScript/ECMAScript regex, not PCRE, Python re, or Go. Most day-to-day syntax is identical, but a few constructs differ: Python's named-group syntax, PCRE's possessive quantifiers and \A/\z, and engine-specific behaviours will not work here. Test in the target language if exact parities matter.
  • Lookbehind support depends on your browser's engine; modern Chromium, Firefox, and Safari all support it, but very old runtimes may not.
  • Highlighting shows the matches, not a full explanation of the pattern's grammar. If a pattern is mis-highlighting, the match list's positions and group values are the fastest way to see what the engine actually captured.