← Back to all posts

How do you test regular expressions online? g/i/m flags and capture groups in one go

An explanation of the g/i/m/s/u/y flags, capture groups and replacement previews using the browser's native RegExp, plus an introduction to the TwoThink regex tester (nothing is uploaded).

You have written a regular expression but you are not confident enough to ship it: a phone number is missing a digit, an email pattern accidentally rejects a valid domain — it is best to try it locally first. regex101 is excellent, but its interface is in English, and in everyday work you often want to test phone numbers, ID numbers or non-ASCII text.

Which flag should you pick

FlagMeaningTypical use
gGlobal, match everythingHighlight every number, bulk replace
iIgnore caseURLs, email domains
mMultiline, ^ $ match per linePulling values out of a log line by line
s. matches newlinesMatching across several lines
uUnicodeEmoji and less common characters
ySticky, match exactly at lastIndexHand-written lexer scanning

Without g the engine only returns the first match — exactly like JavaScript. Turn on g when you want the full list.

Capture groups and replacement

Once you group with parentheses, the replacement template can use $1, $2 or a named group $<year>. The TwoThink regex tester lists the position and the capture groups of every match and previews the replacement result live.

Ready-made patterns

The bottom of the page fills in a template with one click: email, phone number, ID number, YYYY-MM-DD, Chinese characters and more. Adjust it for your own case — that is safer than writing one from scratch.

Is anything uploaded?

No. Matching uses the browser's native RegExp, and the test text only lives in your tab's memory. That makes it suitable for sample strings that contain customer phone numbers or staff IDs.

How it works together with diff and JSON