Regex Tester — Free Online Tool

Test regex patterns live. JavaScript, PCRE, Python regex. Highlight matches, capture groups, regex explanation. Debug email, URL, phone patterns.

Use this free online Regex Tester directly in your browser. No signup required, no data leaves your device. Part of Utilier — a collection of 133+ developer utilities.

What is Regex Tester & Debugger (JavaScript, PCRE, Python, Live Matches)?

Regex tester (regular expression tester) provides interactive environment for testing, debugging, and building regex patterns. Write regex pattern (/^[a-z]+$/), test against input text, see live matches highlighted, capture groups extracted, explanation of pattern parts. Supports multiple regex flavors: JavaScript (ECMAScript), PCRE (PHP, grep), Python, Java, .NET. Features: syntax highlighting (pattern visualization), match highlighting (shows all matches in text), capture group extraction (group 1, 2, 3...), flags (global g, case-insensitive i, multiline m, dotall s), regex explanation (natural language: '^[a-z]+

= 'start, one or more lowercase letters, end'), common patterns library (email, URL, phone, date, IP address), testing suite (multiple test cases: pass/fail), performance analysis (regex performance, catastrophic backtracking detection).

Why use regex tester?

Writing regex = trial and error (hard to visualize). Tester shows exactly what matches, what doesn't, why.

When to use regex tester

Use whenever working with regular expressions.

How to use regex tester

Write regex pattern, test against text, see matches and groups.

  1. Enter regex pattern: Type pattern in regex input: /^[a-z]+$/. Or select from library: email pattern, URL pattern, phone number. Include flags: /pattern/gi (g = global, i = case-insensitive).
  2. Add test text: Type or paste text to test: 'hello world', 'test@example.com', '123-456-7890'. Or upload .txt file (test against large text: log files, data files).
  3. View matches: Matches highlighted in text. Pattern: /\d+/ → '123', '456' highlighted in 'abc123def456'. Count shown: 2 matches. No matches → red border (pattern doesn't match).
  4. Check capture groups: If pattern has groups () → shows extracted values. Pattern: /(\w+)@(\w+)/ → 'user@example.com' → Group 1: 'user', Group 2: 'example'. Copy groups for use in code.
  5. Read explanation: Click 'Explain' → natural language breakdown. /^[0-9]{3}$/ → 'Start of string, exactly 3 digits (0-9), end of string'. Understand each part (^, [0-9], {3}, $).
  6. Test multiple cases: Add test cases: valid inputs (should match), invalid inputs (shouldn't match). Run all → shows pass/fail for each. Example: email pattern → test 'user@example.com' (✓), 'invalid' (✗).
  7. Switch regex flavor (if needed): Select: JavaScript (default), PCRE (PHP), Python, Java, .NET. Pattern /(?<=@)\w+/ (lookbehind) → works in PCRE, Python; not JavaScript (ES2018+ only). Check compatibility.

Key features

Common use cases

Examples

Common regex patterns and explanations.

Email validation

Pattern: /^[\w.-]+@[\w.-]+\.\w{2,}$/
Test: 'user@example.com'
Match: ✓
Explanation: Start (^), username (letters/digits/dot/dash/underscore), @, domain, dot, TLD (2+ letters), end ($).

Simple email validation. Not RFC-compliant (full email regex very complex). Use for basic validation.

Phone number (US)

Pattern: /^\(?(\d{3})\)?[-. ]?(\d{3})[-. ]?(\d{4})$/
Test: '(123) 456-7890'
Match: ✓
Group 1: '123' (area code)
Group 2: '456' (prefix)
Group 3: '7890' (number)
Explanation: Optional parentheses around area code, optional separator (-, ., space).

Matches: (123) 456-7890, 123-456-7890, 123.456.7890. Extract parts using groups.

URL extraction

Pattern: /https?:\/\/[\w.-]+\.[a-z]{2,}(\/[^\s]*)?/gi
Test: 'Visit https://example.com for info'
Match: 'https://example.com'
Explanation: http or https, ://, domain (letters/digits/dot/dash), TLD (2+ letters), optional path.

Global flag (g) finds all URLs. Case-insensitive (i) matches HTTP, Http, http.

Date (YYYY-MM-DD)

Pattern: /^(\d{4})-(\d{2})-(\d{2})$/
Test: '2024-01-15'
Match: ✓
Group 1: '2024' (year)
Group 2: '01' (month)
Group 3: '15' (day)
Explanation: 4 digits (year), dash, 2 digits (month), dash, 2 digits (day).

Basic date format. Doesn't validate: month 1-12, day 1-31. Use date library for full validation.

Hex color code

Pattern: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
Test: '#FF5733'
Match: ✓
Explanation: Hash (#), 6 hex digits (RRGGBB) or 3 hex digits (RGB). Case-insensitive (A-F or a-f).

Matches: #FF5733 (6 digits), #F00 (3 digits, shorthand for #FF0000). Use in CSS, design tools.

Technical reference

Regex syntax and flavor differences:

Basic syntax
. = any char, \d = digit (0-9), \w = word char (a-z, A-Z, 0-9, _), \s = whitespace, ^ = start, $ = end, | = OR. Example: /cat|dog/ matches 'cat' or 'dog'.
Quantifiers
* = 0 or more, + = 1 or more, ? = 0 or 1, {n} = exactly n, {n,} = n or more, {n,m} = n to m. Example: /a{2,4}/ matches 'aa', 'aaa', 'aaaa' (not 'a' or 'aaaaa').
Character classes
[abc] = a or b or c, [a-z] = any lowercase, [^abc] = not a, b, or c, [0-9] = any digit. Example: /[aeiou]/ matches any vowel. /[^0-9]/ matches any non-digit.
Capture groups
(pattern) = capture group. Example: /(\d+)-(\d+)/ → '123-456' → $1='123', $2='456'. Non-capturing: (?:pattern) (group without capturing, faster). Named: (?<name>pattern).
Lookahead/Lookbehind
(?=pattern) = positive lookahead (followed by). (?!pattern) = negative lookahead (not followed by). (?<=pattern) = lookbehind (preceded by). Example: /\d(?= dollars)/ matches '5' in '5 dollars'.
Flags
g = global (all matches, not just first), i = case-insensitive, m = multiline (^ and $ match line start/end), s = dotall (. matches newline), u = Unicode, y = sticky (start at lastIndex).
Escaping
Special chars (. * + ? [ ] { } ( ) ^ $ | \) need escaping: \. \* \+ \? etc. Example: /3\.14/ matches '3.14' (dot literal, not 'any char'). Backslash: \\.
JavaScript regex
/pattern/flags or new RegExp('pattern', 'flags'). Methods: test() (returns true/false), match() (returns matches), replace() (search and replace). Lookahead: yes. Lookbehind: ES2018+.
PCRE (PHP)
preg_match('/pattern/', $string). Supports: lookbehind, named groups, Unicode \p{L}. Differences: \A = start (not ^), \Z = end (not $). More features than JavaScript.
Python regex
import re; re.match(r'pattern', string). r'' = raw string (no escape doubling). Supports: lookbehind, named groups (?P<name>), verbose mode (?x). Similar to PCRE.

Common mistakes to avoid

Forgetting to escape special characters (. + * ? [ ] { } ( ) ^ $ | \)

Why it happens: /3.14/ matches '3.14', '3X14', '3-14' (. = any char). Should be /3\.14/ (dot literal). Special chars have meaning: + = one or more, * = zero or more. Must escape for literal match.

How to avoid it: Escape special chars with backslash: \. \+ \* \? \[ \] \{ \} \( \) \^ \$ \| \\. Example: /\$100/ matches '$100' (dollar literal).

Using greedy quantifiers (.*) instead of lazy (.*?) for extraction

Why it happens: /<div>(.*)<\/div>/ on '<div>A</div><div>B</div>' matches '<div>A</div><div>B</div>' (entire string, greedy). Want: '<div>A</div>' (first div). Greedy = match as much as possible.

How to avoid it: Use lazy quantifier: /<div>(.*?)<\/div>/ (? after quantifier = lazy). Matches: '<div>A</div>' (stops at first </div>). Or use negated class: /<div>([^<]*)<\/div>/.

Not testing edge cases (empty string, Unicode, special chars)

Why it happens: Pattern works on 'normal' input but fails on edge cases. Email pattern /^[\w.]+@[\w.]+\.\w+$/ fails on unicode email (müller@example.com), plus addressing (user+tag@example.com). Production bugs.

How to avoid it: Test edge cases: empty string, Unicode (ñ, é, 你), special chars (!@#$), long input, no input. Add test cases for all scenarios. Regex tester shows: pattern fails on 'müller@example.com'? Fix.

Catastrophic backtracking (slow regex on certain inputs)

Why it happens: Pattern /(a+)+b/ on 'aaaaaaaaaaaaaac' (no 'b') = exponential time (timeout). Backtracking: tries all combinations (a, aa, aaa, ...). DoS vulnerability (malicious input hangs server).

How to avoid it: Avoid nested quantifiers: (a+)+, (a*)*. Use possessive quantifiers (a++, atomic groups) or rewrite: /a+b/ (no nesting). Tester warns (execution > 1s = red flag). Test on long input.

Assuming regex flavor consistency (JavaScript vs PCRE vs Python)

Why it happens: Lookbehind (?<=pattern) works in PCRE, Python, but not JavaScript (ES2018 only, not older browsers). Named groups: JavaScript (?<name>), Python (?P<name>), different syntax. Pattern breaks across languages.

How to avoid it: Select regex flavor in tester. Check documentation: JavaScript (MDN), PCRE (PHP docs), Python (re module). If targeting multiple languages: use common subset (basic regex, no lookbehind).

Frequently asked questions

What is the difference between greedy and lazy quantifiers?

Greedy (* + {n,}) = match as much as possible. Lazy (*? +? {n,}?) = match as little as possible. Example: /a.*b/ (greedy) on 'aXbYb' matches 'aXbYb' (entire). /a.*?b/ (lazy) matches 'aXb' (stops at first b).

How do I test if a regex matches the entire string?

Use anchors: ^ (start) and $ (end). Pattern: /^[a-z]+$/ matches 'hello' (✓), but not 'hello123' (✗, has digits) or 'HELLO' (✗, uppercase). Without anchors: /[a-z]+/ matches 'hello' in 'hello123' (partial).

What are capture groups and how do I use them?

Capture groups (parentheses) extract parts of match. Pattern: /(\d+)-(\d+)/ on '123-456' → Group 1: '123', Group 2: '456'. Use in replace: $1, $2. JavaScript: match()[1], match()[2].

Why doesn't my regex work in JavaScript but works in other tools?

Flavor differences. JavaScript (ES5) doesn't support lookbehind (?<=), named groups (before ES2018). PCRE, Python have more features. Check compatibility: MDN (JavaScript), regex101.com (select flavor).

How do I match Unicode characters (emoji, accents)?

Use Unicode flag: /\p{L}/u (matches any letter, any language). /\p{Emoji}/u (emoji). Or char class: /[\u0080-\uFFFF]/ (non-ASCII). Without u flag: only ASCII. Python: re.UNICODE flag.

What is catastrophic backtracking and how to avoid it?

Exponential time on certain inputs. Pattern: /(a+)+b/ on 'aaac' (no b) = timeout. Avoid: nested quantifiers ((a+)+, (a*)*). Use atomic groups (?>a+) or possessive quantifiers (a++). Test on long input.

Can I use regex for HTML parsing?

No (famous answer: 'you now have two problems'). HTML = context-free grammar (nested tags). Regex = regular grammar (can't handle nesting). Use HTML parser (DOMParser, BeautifulSoup, cheerio). Regex ok for simple extraction (href='url'), not full parsing.

References

Privacy and availability