Dev Toolbox · Windows 10 and 11

Test a regular expression

Type a pattern, paste some text, and every match lights up as you type, with its capture groups listed underneath. The tester uses JavaScript's regular expressions, the flavor of browsers and Node.js, and it runs on your own PC, so log files and customer data are safe to test against.

Updated

How to test a regex

  1. 1

    Open the Regex tester

    In the Dev Toolbox, choose Regex tester in the Check group. It opens with a sample pattern that finds email addresses, so you can see how it works.

  2. 2

    Type your pattern

    Write it in Pattern, without the slashes around it. If the pattern has an error, such as an unclosed group, the message shows under the fields.

  3. 3

    Set the flags

    Type letters into Flags: i to ignore case, m for line-by-line anchors, s to let a dot match line breaks, u for full Unicode.

  4. 4

    Paste test text

    Put it in Test text. Matches shows the count and highlights each match; when the pattern has groups, each match's $1, $2 and so on are listed below.

The flags, and when to use each

FlagNameWhat it does
gglobalFinds every match, not just the first. The tester always looks for all matches, so it makes no difference here.
iignore casecat also matches Cat and CAT.
mmultiline^ and $ match at the start and end of every line, not only of the whole text. Needed for line-by-line work on logs and lists.
sdotAllA dot also matches line breaks, so a pattern can run across lines.
uunicodeTreats emoji and other characters beyond the basic range as one character, enables classes like \p{L} for any letter, and makes syntax errors strict.
ystickyEach match must start exactly where the last one ended, the first at the very start. Used in tokenizers.
dindicesRecords where each group matched, for code that reads match.indices. The highlights look the same.

The Flags field takes only these letters and drops anything else you type into it.

JavaScript regex, and how other flavors differ

Regular expressions look the same everywhere until they do not. This tester runs JavaScript's engine, so a pattern that works here works in browsers, Node.js, Deno and TypeScript. Before copying a pattern into another language, check these:

  • Named groups. JavaScript writes (?<year>\d{4}); Python's re module uses (?P<year>\d{4}).
  • Anchors. JavaScript has no \A or \Z for the very start and end of the text. Use ^ and $ without the m flag instead.
  • Possessive quantifiers such as a++ (PCRE and Java) and recursion such as (?R) (PCRE) do not exist in JavaScript.
  • Unicode classes such as \p{L} need the u flag in JavaScript, and Python's built-in re does not support them at all.
  • Lookbehind, (?<=...), works in JavaScript at any length; some other engines allow only fixed-length lookbehind.

There is no PCRE or Python mode to switch to here. If a pattern is headed for PHP, grep or Python, test the parts these differences touch in that language as well.

Writing patterns that hold up

  • Test what should not match. Paste near-misses next to the good examples: an email address with no dot after the @, a date with month 13. A pattern is only as good as the cases it turns away.
  • Escape special characters you mean literally: . * + ? ^ $ { } ( ) | [ ] and the backslash itself. A bare dot in example.com matches any character, so it would also match examplexcom.
  • Leave out the slashes. /abc/g is how code writes a regex literal. In Pattern type only abc, and put the g in Flags. A / needs no escaping here.
  • Anchor when validating. To check that a whole value is a five-digit ZIP code, write ^\d{5}$, or 123456 will contain a match.
  • Beware nested quantifiers. Patterns like (a+)+$ can take exponentially long on text that almost matches. If the tester stalls while you type one, a server running it would stall on the same input.

Matches of zero length, such as a lone ^ with the m flag, are counted but have nothing to highlight.

From testing to replacing

This tool finds and shows; it has no replace preview. Once the pattern is right, take it to Find and replace in Text Studio: switch on Pattern and it uses the same JavaScript regex, with $1, $2 in the replacement for your groups. That is how you reformat dates, swap first and last names, or clean up a list across a whole text. Common one-off jobs have tools of their own there too: pull out emails and links, remove duplicate lines and sort lines.

Regexes are usually tested on the very data they will run on: server logs with IP addresses and session IDs, exports of customer records, support emails. In Octoolo all of it stays on your computer while you work, and the tester needs no connection.

Questions, answered

Which regex flavor does this tester use?

JavaScript's (ECMAScript), as run by the Chromium engine inside Octoolo. Patterns behave as they do in Chrome, Edge and Node.js.

Why do I see at most 500 matches?

The tester highlights and lists up to 500 matches, and the count stops there too. To look at a later part of a long text, paste just that part or narrow the pattern.

How do I see a capture group's value?

Wrap part of the pattern in parentheses. Under the highlights, each match gets a line such as $1=2024 $2=10, and a group that took no part shows ∅. Named groups are listed by their number.

Why does my pattern show an error?

The engine could not read it. The usual causes are an unclosed ( or [, a quantifier with nothing before it, such as *abc, or a \ at the very end. The message names the problem.

Does a pattern match across lines?

When it allows it, yes. \s and negated classes like [^x] already cross line breaks, while a dot does so only with the s flag. To work line by line, use ^ and $ with the m flag.

Can I test a pattern meant for Python or PHP here?

Only the parts the flavors share. Character classes, quantifiers, groups and lookahead behave the same; named-group syntax, possessive quantifiers and some anchors differ, as listed above.

Regex tester, and 16 more apps.

Download for Windows

7 days free, then from $3.99 a month for all 17 apps. Windows 10 and 11.