Regex Tester — Test Regular Expressions Online
Test regular expressions in real time. Match highlighting, group capture, and flag controls (g, i, m).
About Regex Tester — Test Regular Expressions Online
Regex Tester lets you test JavaScript regular expressions in real time with color-highlighted matches, captured group extraction, and instant flag (g/i/m/s) toggling — all in the browser with no sign-up required.
How to Use
- 1Enter your regular expression in the pattern field at the top.
- 2Toggle flags — g (global), i (case-insensitive), m (multiline), s (dotAll) — as needed.
- 3Type or paste your test string. Matches are highlighted on the right instantly.
- 4Check the match list below for index positions and captured group values.
Features
- Real-time highlighting — matches appear as you type
- g / i / m / s flags toggled with a single click
- Captured group values and index positions listed per match
- Invalid patterns detected instantly with an error badge
- Runs entirely in the browser — no upload or sign-up required
Regex Syntax Quick Reference
Regular expressions use a compact syntax of special characters to describe text patterns. This reference covers the most commonly used constructs in JavaScript regex.
Character Classes, Quantifiers, Anchors, and Groups
Character classes match any one character from a set: [abc] matches a, b, or c; [a-z] matches any lowercase letter; [^abc] matches anything except a, b, or c. Shorthand classes include \d (digit 0-9), \w (word character: letters, digits, underscore), \s (whitespace). Quantifiers control repetition: * means zero or more, + means one or more, ? means zero or one, {n} means exactly n, {n,m} means between n and m. Anchors assert position: ^ matches the start of a line, $ matches the end. Parentheses () create capturing groups; (?: ) creates non-capturing groups. The | character means OR between alternatives.
Lookaheads, Lookbehinds, and Common Metacharacters
Lookaheads assert what follows without consuming characters: (?=foo) matches a position followed by "foo", (?!foo) asserts not followed by "foo". Lookbehinds work similarly for preceding text: (?<=foo) and (?<!foo). The dot . matches any character except newline (unless the s/dotAll flag is enabled). Backslash escapes special characters: \. matches a literal dot, \( matches a literal parenthesis. Common pitfalls include forgetting to escape dots in patterns like IP addresses (use \d+\.\d+\.\d+\.\d+ not \d+.\d+.\d+.\d+) and using greedy quantifiers when lazy ones (\d+?) are needed.
Practical Regex Patterns
Learning regex syntax is most effective with concrete examples. These patterns cover common validation and extraction tasks in web development.
Email, URL, Date, and Phone Patterns
A basic email pattern is /^[^\s@]+@[^\s@]+\.[^\s@]+$/ — this is intentionally simple; full RFC 5321 compliance requires a much more complex pattern. For URLs, /https?:\/\/[^\s]+/ matches http and https URLs. Common date formats: /\d{4}-\d{2}-\d{2}/ matches ISO 8601 (YYYY-MM-DD), /\d{1,2}\/\d{1,2}\/\d{2,4}/ matches MM/DD/YYYY or similar. US phone numbers: /\(\d{3}\)\s*\d{3}-\d{4}/ matches (555) 123-4567. IPv4 addresses: /\b(?:\d{1,3}\.){3}\d{1,3}\b/ matches the pattern but does not validate that each octet is 0-255.
Common Gotchas and Debugging Tips
The most common regex mistake is catastrophic backtracking — a pattern like (a+)+ applied to a long string with no match can freeze the browser by exploring an exponential number of combinations. Avoid nested quantifiers on overlapping patterns. Another frequent error is forgetting the global g flag when you want all matches (without it, String.match() returns only the first). When a pattern is not matching as expected, simplify it step by step and test each part independently using this tool. Use anchors (^ and $) deliberately — leaving them out allows partial matches you may not have intended.
FAQ
- Which regex engine does this tool use?
- It uses JavaScript's built-in RegExp engine, which follows the ECMAScript standard and is compatible with JS code.
- Can I test named capture groups?
- Yes. Named groups defined with (?<name>...) syntax are displayed in the match results.
- What flags are supported?
- g (global), i (case-insensitive), m (multiline), and s (dotAll) are available as toggles.
- Does it support Unicode regex (u flag)?
- The u flag is not shown as a toggle but you can include it in your pattern string directly if needed.
- Is there a character limit for the test string?
- There is no hard limit, but very large inputs may slow down the browser. The match list is capped at 100 results for performance.
Found a bug or something not working as expected?
Report a bug →