Regex Tester
Test regular expressions with live highlighting
How to use Regex Tester
Test and debug regular expressions with live match highlighting. Supports flags and groups. Free online regex tester tool.
What are regular expressions used for?
Regular expressions (regex) are patterns that match text. Mastering them multiplies a developer's productivity — tasks that would require 50 lines of string manipulation code can be solved with a single regex.
- Input validation: Validate email addresses, phone numbers, postal codes, credit card numbers, and passwords against format rules before processing.
- Data extraction: Extract specific patterns from text — all URLs in a document, all dates in a log file, all ISBN numbers in a catalog.
- Search and replace: Perform complex text transformations — reformat dates, anonymize data, normalize whitespace, or extract named capture groups.
- Log file analysis: Parse server logs, application logs, and event streams — extract IP addresses, error codes, and timestamps using pattern matching.
- Code refactoring: Find all function calls matching a specific signature, or identify deprecated API usage across a codebase.
Common patterns: \d+ matches one or more digits. \w+ matches a word. ^ matches start of line, $ matches end. [A-Z] matches uppercase letters. (group) captures a group. a|b matches a or b.
Frequently Asked Questions
What do the regex flags g, i, m, and s mean?
g (global): find all matches, not just the first. i (case-insensitive): match regardless of case. m (multiline): ^ and $ match start/end of each line, not just the whole string. s (dotAll): the dot (.) matches newlines too. Flags are combined: /pattern/gim matches all occurrences, case-insensitively, across multiple lines.
What is the difference between greedy and lazy matching?
Greedy quantifiers (+, *, {n,}) match as much as possible. <.+> matches the entire string '<b>bold</b>' as one match. Lazy quantifiers (+?, *?, {n,}?) match as little as possible. <.+?> matches '<b>' and '</b>' separately. Use lazy matching when extracting individual HTML tags or bracketed expressions.
What is a capture group vs a non-capturing group?
(pattern) is a capturing group — the matched text is stored and can be referenced as $1, $2, etc. in replacements. (?:pattern) is a non-capturing group — it groups the pattern for quantifiers or alternation without storing the match. Use non-capturing groups when you need grouping but do not need the captured value.
What is a lookahead and lookbehind?
Lookahead (?=pattern) asserts that what follows matches the pattern, without consuming characters. Lookbehind (?<=pattern) asserts what precedes. Negative versions: (?!pattern) and (?<!pattern). Example: \d+(?= dollars) matches numbers followed by ' dollars' without including 'dollars' in the match.
Why does my regex work in JavaScript but not in Python?
Regex flavors differ slightly between languages. Python uses \A and \Z for string start/end (vs ^ and $). Python raw strings (r'pattern') avoid double-escaping backslashes. JavaScript does not support lookbehind in older engines. PCRE (PHP, Perl) has features (atomic groups, possessive quantifiers) not in all engines. Always test regex in the target language.
Regex vs string methods vs parser vs AI
Regex is ideal for pattern-based matching and extraction — powerful but cryptic. String methods (split, indexOf, slice) are clearer for simple operations and should be preferred when regex is overkill. Dedicated parsers (HTML parsers, JSON parsers, CSV parsers) are always preferred over regex for structured formats — do not parse HTML with regex. AI-assisted parsing handles ambiguous natural language where patterns are unpredictable. Use the simplest tool that solves the problem.