Regex Tester

Test and debug regular expressions with live match highlighting. Supports global, case-insensitive, and multiline flags. Quick-insert tokens for common patterns.

awaiting pattern
Regular expression
Flags
Quick insert
\d+ digit \w+ word \s+ space [a-z]+ ^ start $ end ( ) group \b boundary [^\s]+ \d{4} decimal email
Test string
Matches highlighted (click to copy)

How to Use the Regex Tester

  1. Enter your regex pattern β€” type or paste your regular expression in the pattern field (without surrounding slashes).
  2. Set flags β€” common flags: g (global β€” find all matches, not just first), i (case-insensitive), m (multiline β€” ^ and $ match line starts/ends).
  3. Paste your test string β€” enter the text you want to match against in the test string area.
  4. See matches highlighted β€” all matches are highlighted in the test string. Match groups are shown separately.
  5. Test edge cases β€” add multiple lines including edge cases (empty strings, special characters, boundary conditions) to ensure your regex works correctly.
⚑ Regex quick start: \d = any digit. \w = word character (letter/digit/underscore). \s = whitespace. . = any character. * = zero or more. + = one or more. ? = zero or one. ^ = start of string. $ = end of string. [abc] = character class. (abc) = capture group. | = or.

Understanding Regular Expressions

πŸ”€ Character Classes
\d matches 0-9. \D matches non-digits. \w matches [a-zA-Z0-9_]. \W matches non-word characters. \s matches whitespace (space, tab, newline). [aeiou] matches any vowel. [^aeiou] matches any non-vowel. [a-z] matches any lowercase letter.
πŸ“Š Quantifiers
* = zero or more (greedy). + = one or more (greedy). ? = zero or one. {n} = exactly n times. {n,} = n or more times. {n,m} = between n and m times. Adding ? after quantifier makes it lazy (matches as few as possible): *? +? {n,m}?
βš“ Anchors
^ matches start of string (or line with m flag). $ matches end of string (or line with m flag). \b matches word boundary (between \w and \W). \B matches non-word boundary. These zero-width assertions match positions, not characters.
🎯 Groups and Captures
(abc) creates a capture group β€” the matched text is captured and available as a back-reference. (?:abc) is a non-capturing group β€” groups without capturing, useful for applying quantifiers. (?abc) named capture group. Back-references: \1 refers to first capture group in the pattern.
πŸ” Lookahead/Lookbehind
(?=abc) positive lookahead β€” matches position followed by 'abc'. (?!abc) negative lookahead. (?<=abc) positive lookbehind β€” matches position preceded by 'abc'. (?
⚠️ Greedy vs Lazy
By default, quantifiers are greedy β€” they match as much as possible. Pattern .+ on 'aXbXc' matches 'aXbXc' (entire string). Lazy .+? matches 'a' (minimum). Greedy is usually what you want for simple patterns; lazy is needed when you want to stop at the first occurrence of a delimiter.

Practical Regex Applications

Common validated patterns

Email validation: `/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/`. URL matching: `/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/`. Phone (flexible): `/^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/`. IP address: `/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/`. These patterns cover most common validation needs.

Regex in text processing pipelines

Command line: `grep -E 'pattern' file` extracts matching lines. `sed 's/pattern/replacement/g'` performs find-and-replace. `awk '/pattern/{print}'` filters and processes. These tools make regex essential for log analysis, data extraction, and text transformation in Unix pipelines. A single regex command can process millions of log lines in seconds β€” tasks that would take hours in a GUI.

Performance considerations

Poorly written regex can cause catastrophic backtracking β€” exponential time complexity for certain inputs. The classic example: `(a+)+` on a string like 'aaaaaaaaaaaaaab' can take seconds or minutes. This vulnerability is called ReDoS (Regular Expression Denial of Service). Avoid nested quantifiers on the same character class. Test regex performance with edge cases including strings that almost match. Tools like regex101.com show match steps to identify backtracking issues.

πŸ”§ Regex debugging tips: Use regex101.com for step-by-step explanation of how your pattern matches. Start simple and build up complexity incrementally β€” test each addition before continuing. Include tests for empty strings, boundary cases, and strings that should NOT match. Comment complex regex using the verbose mode (/pattern/x in some languages) which allows whitespace and # comments.

Frequently Asked Questions

What is a regular expression?
A regular expression (regex) is a pattern used to match, search, and manipulate text. It uses special characters like \d (digit), \w (word character), ^ (start), $ (end), and + (one or more) to define flexible search patterns.
What do the regex flags mean?
g (global) finds all matches, not just the first. i makes the match case-insensitive. m (multiline) makes ^ and $ match start/end of each line, not just the whole string. You can combine flags: gi = global and case-insensitive.
How do I match a specific word?
Use \bword\b β€” the \b is a word boundary anchor that ensures you match the full word, not part of a longer word. Example: \bcat\b matches 'cat' but not 'catch' or 'concatenate'.
How do I create a capture group?
Wrap part of your pattern in parentheses: (\d{4}) captures a 4-digit number. Named groups use (?<name>...). Groups are shown in the match info panel and can be referenced in replacements.
Why is my regex matching too much?
Use quantifier qualifiers: + is greedy (matches as much as possible). +? is lazy (matches as little as possible). Example: <.+> matches the entire string if there are multiple tags, while <.+?> matches each tag individually.