Skip to main content
Tools

Regex Tester

Test JavaScript regular expressions live: highlight matches, list groups, preview replacements, with a syntax explainer and common patterns.

/g
Flags

0 characters · 1 line

Matches

Explanation

Type a regular expression to see each part explained here.

Common patterns

These patterns only check the rough shape and do not guarantee the data is valid (for example, whether an email address exists). Adjust them as needed.

  • Email/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gi
  • URL (http/https)/https?:\/\/[\w-]+(?:\.[\w-]+)+(?::\d+)?(?:[/?#][^\s]*)?/gi
  • Taiwan mobile number/09\d{2}-?\d{3}-?\d{3}/g
  • Taiwan landline/\(?0\d{1,3}\)?[-\s]?\d{3,4}-?\d{4}/g
  • Taiwan postal code (3, 5 or 6 digits)/(?<!\d)\d{3}(?:\d{2,3})?(?!\d)/g
  • IPv4 address/\b(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\b/g
  • Date YYYY-MM-DD/(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])/g
  • Time HH:MM(:SS)/\b(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?\b/g
  • Hex color/#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4})\b/g
  • UUID/\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/gi
  • Number (with separators, decimals)/-?\d{1,3}(?:,\d{3})*(?:\.\d+)?|-?\d+(?:\.\d+)?/g
  • Chinese characters/\p{Script=Han}+/gu

How to use

  1. Type the pattern under “Regular expression” (without the surrounding slashes) and tick the flags you need, such as g (all matches) or i (ignore case).
  2. Paste text into “Test text”. Matches are highlighted instantly, and the table below lists every match and its groups.
  3. Optionally type a replacement, using $1 or $<name> for groups, to preview the replaced text.
  4. If the syntax is unfamiliar, read the “Explanation” of each part, or start from one of the “Common patterns”.

FAQ

Is my data uploaded?

No. Matching runs in your browser, and neither the pattern nor the text leaves your device.

Which regex flavor is this?

Your browser’s built-in JavaScript (ECMAScript) regular expressions, so results match new RegExp() in your code. Other flavors (PCRE, Python, Java) share most syntax but differ in details: in JavaScript, \w only matches ASCII letters, digits and underscores, not Chinese characters.

How do I match Chinese characters?

Turn on the u flag and use \p{Script=Han}; \p{Script=Han}+ matches a run of Chinese characters, as in the common patterns. Without the u flag, an emoji counts as two characters.

Can I use the common patterns for validation?

They only check the rough shape: a mobile number is 10 digits starting with 09. They cannot tell whether a number or an email address actually exists, so combine them with other checks for real validation.

Why was matching stopped?

Some patterns, such as (a+)+$, need exponentially many attempts on certain text and can freeze a browser for a long time. To keep the page responsive, matching runs in the background and stops after 3 seconds with a notice. A more specific pattern (here a+$) usually fixes it.

Why are positions different from what I count?

Positions are JavaScript string indices in UTF-16: a Chinese character takes 1, but an emoji or other rare character takes 2. They equal match.index in your code.

Keyboard shortcuts

/
Search tools (on a tool page, goes to the homepage search)
?
Show this help
Esc
Close a dialog
Ctrl / ⌘Enter
Run the tool's main action (where supported)

While you type in a text field, / and ? are typed as usual.