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
| Flag | Meaning | Typical use |
|---|---|---|
g | Global, match everything | Highlight every number, bulk replace |
i | Ignore case | URLs, email domains |
m | Multiline, ^ $ match per line | Pulling values out of a log line by line |
s | . matches newlines | Matching across several lines |
u | Unicode | Emoji and less common characters |
y | Sticky, match exactly at lastIndex | Hand-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
- To compare a config before and after a change: use the text diff
- To validate an API response: use the JSON formatter
- To test a string rule: use the regex tester