Regex Tester
Test regular expressions with real-time match highlighting and capture groups. 100% client-side.
How to Use the Regex Tester
- Enter your regex pattern in the pattern field at the top. Do not include the surrounding slashes or flags — those are handled separately.
- Select flags by clicking the flag chips. The
g(global) flag is enabled by default to find all matches. Flags toggle independently. - Type or paste your test string in the textarea below. Matches are highlighted in real time as you type.
- Review matches — the highlighted output shows matches marked in yellow, and the match table below lists each match with its index position and capture groups.
Understanding Regular Expressions
Regular expressions are one of the most powerful tools in a developer's arsenal. They provide a concise and flexible way to search, match, and manipulate text. Every programming language has some form of regex support, and mastering regex patterns can dramatically improve your ability to process text data, validate user input, and parse structured content.
Common Regex Patterns
- Email validation:
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} - URL matching:
https?://[^\s/$.?#].[^\s]* - IP address:
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b - Phone number:
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} - 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
Once you have validated your text with regex, you may want to compare results using our Diff Checker or transform text casing with the Case Converter. For structured data validation, try the JSON Formatter.
Regex Flags Explained
JavaScript supports several flags that modify how the regex engine behaves. The g (global) flag finds all matches instead of returning after the first match. The i (case-insensitive) flag treats uppercase and lowercase letters as equivalent. The m (multiline) flag changes the behavior of ^ and $ so they match the start and end of each line rather than the entire string. The s (dotAll) flag allows the dot . to match newline characters. The u (unicode) flag enables full Unicode matching.
Capture Groups
Parentheses in a regex create capture groups that extract specific parts of a match. For example, the pattern (\d{4})-(\d{2})-(\d{2}) applied to "2026-03-22" captures three groups: "2026", "03", and "22". Named capture groups using (?<name>...) syntax make your regex more readable and the extracted values easier to reference in code. This tool displays all capture groups in the match details table.
Performance Considerations
Regex engines can exhibit catastrophic backtracking on certain patterns, causing extreme slowness. Avoid nested quantifiers like (a+)+ or (a*)*. Be specific with your character classes rather than using broad wildcards. When matching large texts, prefer non-greedy quantifiers (*?, +?) when possible to reduce unnecessary backtracking.
Lookaheads and Lookbehinds
Lookaheads ((?=...) for positive, (?!...) for negative) and lookbehinds ((?<=...) for positive, (?<!...) for negative) match positions without consuming characters. For example, \d+(?= dollars) matches the number in "100 dollars" but not in "100 euros". Lookbehinds work similarly but check what precedes the current position. These are powerful for extracting data from structured text without including surrounding context in the match. Note that JavaScript lookbehinds require a modern browser (Chrome 62+, Firefox 78+, Safari 16.4+).