Home/Dev Tools/Regex Tester

Regex Tester

Validate

Test regular expressions with live match highlighting and flag controls.

//g
Flags
Input
Loading editor…
Paste test text in the left pane…
✨ AI Code Explanation
Mode

What Is a Regular Expression (Regex)?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regex is used to find, validate, extract, and replace text in strings. JavaScript's built-in RegExp engine supports the ECMAScript regex standard — the same one used in all modern browsers and Node.js. Developers reach for regex constantly: validating input formats, scraping structured data, refactoring code, or building lexers.

Regex Tester Online — What This Tool Does

This free regex tester evaluates your JavaScript regular expression against any test string with live match highlighting, flag toggles, named capture groups, and a Replace mode for testing substitutions. Includes 12 preset patterns (email, URL, IPv4, date, JWT, hex colour, semver, and more) and full Unicode support. Runs entirely in your browser — no remote evaluation.

How to Use This Regex Tester — Step by Step

  1. Type your regex pattern into the /pattern/ field (without the outer slashes).
  2. Toggle flags as needed — g is on by default to find all matches.
  3. Paste your test string into the left pane — matches highlight live as you type.
  4. The match list on the right shows each match's start index, length, captured value, and named groups.
  5. Switch to Replace mode to test substitutions using backreferences like $1, $2, or named groups $<name>.
  6. Use the Presets dropdown to load common patterns (email, URL, IPv4, date, JWT, etc.).
  7. Click Copy to copy all match results as plain text.

JavaScript Regex Flags Explained

  • gGlobal: find all matches, not just the first. Required for String.matchAll().
  • iCase-insensitive: /hello/i matches Hello, HELLO, and hello.
  • mMultiline: ^ and $ match the start and end of each line, not just the whole string.
  • sDotAll: makes . match newline characters (\n, \r) in addition to everything else.
  • uUnicode: enables full Unicode code point matching and strict syntax — required for emoji and multi-byte character patterns.

Capture Groups and Named Groups

Capture groups — written as (...) — extract specific parts of a match. Named groups use the syntax (?<name>...) and appear in the match list under their name rather than a numeric index. In Replace mode, reference numbered groups with $1, $2, etc., and named groups with $<name>. Non-capturing groups (?:...) group without creating a backreference.

Common Regex Patterns

  • Email: [a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}
  • URL (http/https): https?:\/\/[\w\-.~:/?#\[\]@!$&'()*+,;=%]+
  • Date (YYYY-MM-DD): \d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
  • Hex color: #(?:[0-9a-fA-F]{3}){1,2}\b
  • IPv4 address: \b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b
  • JWT token: ey[A-Za-z0-9_-]+\.ey[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+
  • Semantic version: \bv?\d+\.\d+\.\d+\b

Common Regex Mistakes to Avoid

  • Forgetting the g flag — without global, only the first match is returned. Enable g to find all occurrences.
  • Catastrophic backtracking — patterns like (a+)+ on long strings can hang the browser. Avoid nested quantifiers on overlapping patterns.
  • Not escaping special characters — characters like . * + ? ^ $ { } [ ] | ( ) have special meaning and must be escaped with \ when used literally.
  • Using . to match newlines. does not match \n by default. Enable the s (dotAll) flag if you need cross-line matches.
  • Anchoring confusion^ and $ match the whole string by default. Enable the m flag to match line boundaries instead.

Tips & Tricks

  • Use Presets as starting points — the email, URL, JWT, and IPv4 patterns work out of the box and are battle-tested. Edit from there for your specific case.
  • Replace mode for refactoring — paste a code block, write a pattern with capture groups, and use $1 / $2 in the replacement. Faster than a full IDE find-and-replace for one-off jobs.
  • Anchor for performance — adding ^ and $ tells the engine to stop early on non-matches. Massive speedup on large inputs.
  • Non-capturing groups — use (?:...) when you need grouping but not capture. Cleaner match output and faster engine.
  • Lookahead & lookbehind(?=...) for positive lookahead, (?<=...) for positive lookbehind. Match X only if followed/preceded by Y without consuming Y.

Regex Engines Differ — JavaScript vs PCRE vs Python

This tester uses the JavaScript (ECMAScript) regex engine. Patterns that work here may behave differently in PCRE (PHP, Apache .htaccess), Python's re module, or Go's regexp. The most common differences: lookbehind support (universal in JS now), named groups syntax ((?P<name>...) in Python vs (?<name>...) in JS), and possessive quantifiers (PCRE only).

Related Tools

  • JWT Decoder — Decode and inspect JSON Web Tokens (the payload uses Base64URL encoding).
  • URL Encoder / Decoder — Encode or decode special characters in URLs and query strings.
  • Hash Generator — Generate MD5, SHA-256, and other cryptographic hashes from any string.
  • Text Diff Checker — Compare two strings line-by-line to see what changed.

Is My Pattern or Test String Sent to a Server?

No. Pattern compilation and matching run entirely in your browser using the native JavaScript RegExp engine. Your patterns, test strings, and matches are never transmitted — useful when testing patterns against real user data, log lines, or proprietary code that shouldn't leave your machine.