Regex Tester

Test regular expressions live with match highlighting, flags, and group capture support.

Regex Tester

Examples:
//
Preview
Contact us at hello@example.com or support@foo.io for help.
2 matches found
1hello@example.comat index 14
2support@foo.ioat index 35

How to Use

1

Enter your regex pattern

Type the regular expression (without delimiters) — syntax errors are flagged immediately.

2

Provide a test string

Enter the text to match against. Use multiple lines to test various inputs simultaneously.

3

Select regex flags

Toggle g (global), i (ignore case), m (multiline), and s (dotall) flags to control matching behavior.

4

Inspect matches and capture groups

View highlighted matches and inspect each capture group's extracted substring in the results panel.

What is a Regular Expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. They are used in programming for string validation, parsing, search-and-replace, and data extraction. Common use cases include validating emails, URLs, and phone numbers.

Real-World Examples & Use Cases

Form Input Validation in Web Development

Front-end developers implement client-side validation for email addresses, phone numbers, postal codes, credit card numbers, and custom format requirements using regular expressions. A regex tester lets developers build and verify these patterns interactively: /^[\w.+-]+@[\w-]+\.[\w.]{2,}$/ for email validation. Testing against dozens of valid and invalid email formats immediately reveals edge cases: does it accept user.name+tag@subdomain.example.co.uk correctly? Does it reject missing @ symbols and double dots?

Log File Parsing and Data Extraction

DevOps engineers and developers extracting data from server logs, application logs, and monitoring outputs use regex to isolate relevant fields. An Apache access log line contains IP address, timestamp, HTTP method, URL, status code, and response size — a single regex with named capture groups extracts all fields simultaneously. Testing against sample log lines in a regex tester verifies the pattern works on real data before embedding it in log parsing scripts or monitoring alert rules.

Code Search and Refactoring

Developers using regex-aware search tools (grep, VS Code find, sed) to refactor code need to verify their patterns won't match unintended code. A regex tester helps build and test find-and-replace patterns: finding all usages of an old API method, extracting version numbers from package.json, or replacing deprecated function calls with new APIs. Testing the pattern against representative source code snippets before running globally prevents accidental replacements.

Text Processing and Data Pipeline Development

Data engineers building text processing pipelines use regex for tokenization, field extraction, and data cleaning. Patterns for extracting dates from unstructured text, normalizing phone number formats, identifying currency amounts, or parsing semi-structured log data are all built iteratively. A live regex tester shortens the iteration cycle dramatically — adjust the pattern, see matches update instantly — compared to writing and running a script for each test.

How It Works

Regular Expression Syntax Reference: Character classes: . Any character (except newline, unless s flag) \d Digit [0-9] \w Word character [A-Za-z0-9_] \s Whitespace [\t\n\r\f\v ] \D, \W, \S Negated versions [abc] Character set (a or b or c) [^abc] Negated set (not a, b, or c) [a-z] Range Anchors: ^ Start of string (or line with m flag) $ End of string (or line with m flag) \b Word boundary \B Non-word boundary Quantifiers (greedy by default): * 0 or more + 1 or more ? 0 or 1 {n} Exactly n {n,} n or more {n,m} Between n and m Add ? to make lazy: *?, +?, {n,m}? Groups: (abc) Capturing group (?:abc) Non-capturing group (?<name>abc) Named capturing group (?=abc) Positive lookahead (?!abc) Negative lookahead (?<=abc) Positive lookbehind (?<!abc) Negative lookbehind Common patterns: Email: [\w.+-]+@[\w-]+\.[\w.]{2,} URL: https?://[\w.-]+\/?[\S]* Date: \d{4}-\d{2}-\d{2} IPv4: \d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}

Frequently Asked Questions

What does the global (g) flag do in regex?
Without the g flag, a regex match stops at the first match found. With g (global), the engine finds all non-overlapping matches in the string from left to right. In JavaScript: string.match(pattern) with g flag returns an array of all matches; without g, it returns only the first match with capture group details. The g flag is essential for search-and-replace operations that should replace all occurrences (String.replace() with g replaces all; without g, only the first is replaced).
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*,+,{n,m}) match as many characters as possible while still allowing the overall pattern to succeed. Lazy quantifiers (*?,+?,{n,m}?) match as few characters as possible. Example: matching HTML tags in '<b>bold</b> and <i>italic</i>' with greedy <.*> matches the entire string from first < to last >. Lazy <.*?> matches '<b>' then stops. For HTML parsing, lazy is usually correct. Greedy is default because most patterns want the longest possible match.
How do capture groups work?
Capture groups, written as (pattern), extract specific parts of a match. Example: date pattern (\d{4})-(\d{2})-(\d{2}) applied to '2024-01-15' creates three capture groups: group 1 = '2024', group 2 = '01', group 3 = '15'. Named groups (?<year>\d{4}) let you reference captures by name: match.groups.year = '2024'. Non-capturing groups (?:pattern) group without extracting. Capture groups are referenced in replacements: '2024-01-15'.replace(/(\d{4})-(\d{2})-(\d{2})/, '$2/$3/$1') = '01/15/2024'.
Why does my regex work in one language but not another?
Regex syntax varies between languages and engines. JavaScript, Python, Java, PCRE (PHP, Perl), and .NET regex all support the core syntax but differ on: lookbehind (JavaScript only recently added it, with restrictions), named groups syntax ((?P<name>) in Python vs (?<name>) in modern JS), possessive quantifiers (++ only in Java/PCRE), backreferences, and Unicode handling. When copying a regex from one language to another, verify the specific features used are supported in the target language's regex engine.
What is catastrophic backtracking?
Catastrophic backtracking (also called ReDoS — Regular Expression Denial of Service) occurs when a poorly written regex takes exponential time to fail on a non-matching string. Classic example: (a+)+ on a string of 'a' characters followed by 'b'. For each 'a', the engine tries all ways to distribute them among the nested groups before concluding no match. On 30 'a' characters, this can cause billions of steps. Defense: avoid nested quantifiers on the same character class, use possessive quantifiers or atomic groups where available, and test patterns against long non-matching strings before deploying in production.

Related Tools

Explore other tools in this category.

Looking for something else?