← Back

Regex Tester

Match in real time with highlighted results

Common templates (click to apply)
Regular expression
Flags
Matches (4)
1023index 5
58index 13
199index 19
5index 23

About Regex Tester

This tool lets you check a regular expression quickly in your browser. You enter a pattern, some flags and a block of test text, and the page lists every piece of the text that matched, together with the position (index) where each match starts. It uses the browser's built-in JavaScript RegExp engine, so a pattern that works here will work in JavaScript code. It is worth being clear about what it does not do: it does not paint highlights over your text (matches are shown as a list), and it does not do replacements, show capture-group details or generate code. It answers one question only - what does this pattern actually match in this text?

How to use it

  1. Click a button under 'Common templates (click to apply)', such as 'Email' or 'Date (YYYY-MM-DD)'. The pattern is dropped into the 'Regular expression' box. You can also type your own; the starting value is \d+.
  2. Set the 'Flags' field. It starts as g (global). The field accepts only the letters g, i, m, s, u and y; anything else you type is stripped out.
  3. Paste or type the text to check into 'Test text'. The default is a short sentence containing an order number, a quantity and a price.
  4. After you stop typing for about 0.3 seconds, a 'Matches (N)' section appears, where N is the total number of matches. Each row shows the matched text and its index. If nothing matches you see 'No matches', and if the pattern is invalid the heading changes to 'Error' and shows the browser's message.
  5. Adjust the pattern or text until the results are what you expected, then copy the pattern into your code.

A worked example

Take the default test text '订单号 A1023,数量 58,价格 199.5' (order number A1023, quantity 58, price 199.5). The pattern \d+ with the g flag returns four matches when run: 1023 (index 5), 58 (index 13), 199 (index 19) and 5 (index 23). The decimal 199.5 has been split in two by the dot. Switch to the 'Integer/decimal' template, -?\d+(\.\d+)?, and you get three matches: 1023 (index 5), 58 (index 13) and 199.5 (index 19). With the email template, [\w.-]+@[\w-]+\.[\w.-]+, run against '联系 zhang.san@example.com 或 li-si@mail.cn', the matches are zhang.san@example.com (index 3) and li-si@mail.cn (index 27). Comparing results like this is a quick way to spot a pattern that is too loose or too strict. All of these results were produced by running the same RegExp logic, not estimated.

Supported features and known limits

  • Only JavaScript regex syntax is supported. Python, Java and PCRE differ in named-group syntax, lookbehind support, inline modifiers and more, so passing here does not guarantee it will pass in another language.
  • Allowed flags are g, i, m, s, u and y. Newer flags such as d or v are filtered out of the field and cannot be used.
  • The tool lists all matches whether or not you include g (it adds global matching internally), so you cannot see the 'first match only' behaviour of a non-global pattern.
  • The list shows at most the first 30 matches. The number in the heading is still the true total. If you have more, shorten the text or tighten the pattern.
  • Only the whole match and its index are shown. Capture group contents are not displayed; rewrite the pattern temporarily if you need to inspect a group.
  • A pattern that can match an empty string (such as x*) produces an empty match at every position, so you will see many blank rows. That is how regular expressions behave, not a display fault.
  • The built-in templates are simplified starting points. For example, the ID number template only checks for 17 digits followed by a digit or X, and the phone template only checks for a leading 1, a second digit from 3 to 9, then nine more digits. They do not verify that anything is real and should not be used as strict validation.

Why does it match here but behave differently in my code?

There are three usual causes. First, a different regex engine, as noted above. Second, string escaping: in a JavaScript string literal you must double the backslash ("\\d"), whereas in this tool's input box you type a single \d. Do not mix the two when copying. Third, missing flags: if your code does not use g or i, the results will naturally differ.

What does the 'Error' message mean?

The message comes straight from the browser's RegExp constructor and normally names the problem. For example, an unclosed parenthesis gives 'Invalid regular expression: /(abc/g: Unterminated group'. Typical causes are unbalanced brackets, a quantifier with nothing to repeat, a character class with a reversed range, or an escape that is not allowed under the current flags. Fix those first and the results will return.

Why don't results update on every keystroke?

Input is debounced by 300 milliseconds, so matching runs only once you pause. This avoids running a half-typed pattern at every step. It does not remove the risk of catastrophic backtracking: a pattern with nested quantifiers such as (a+)+b on a long run of a characters can still freeze the page. Debouncing only makes that less likely while you are typing. If the page hangs, close the tab and simplify the pattern.

Can I use the built-in validation templates in a real form?

I would not ship them unchanged. The 'Password strength' template uses lookaheads to require a lowercase letter, an uppercase letter, a digit and at least eight characters, but says nothing about other characters. The 'Port number' template spells out ranges up to 65535, yet without ^ and $ anchors it can still match part of a longer number in the middle of text. Treat the templates as a starting point, adapt them to your own rules and test them properly.

How is the index calculated?

The index is the JavaScript string position, counted from 0 in UTF-16 code units. An ordinary Chinese character takes one unit, so in the example '订单号 A' takes five positions (including the space) and the digits 1023 after it begin at index 5. Some emoji and rare characters take two units, which makes later indexes larger than a visual count would suggest.

Privacy and processing

Matching happens entirely in your browser using the built-in RegExp engine. The code makes no network request with your pattern or test text, and nothing is saved when you close or refresh the page. If you paste sensitive text into the test box, it stays in the memory of that page only, but it is still sensible not to leave the page open on a shared computer.