Regex Tester & Debugger Online

Enter a regular expression and test string to instantly see highlighted matches, capture groups, and replacement results. Completely free and runs entirely in your browser.

/ /
Matches: 0 Groups: 0 Steps: <1ms
Matches will be highlighted here...

Common Regex Patterns Reference

NamePatternDescription

Built-In Features

Real-Time Match Highlighting

See your matches highlighted instantly as you type your regular expression and test string. Every match is color-coded directly within the test string so you can visually verify that your pattern is capturing exactly the right content. The highlighting updates in real time with no button clicks required, making it effortless to iterate on your pattern until it is correct. Alternating highlight colors help distinguish adjacent matches that would otherwise blend together.

Capture Group Inspector

When your regex contains capturing groups defined by parentheses, this tool displays every group for every match in a structured table. You can see the full match alongside each numbered or named group, making it simple to verify that your groups are extracting the intended substrings. This is invaluable when building patterns for data extraction tasks where you need to pull specific fields out of a larger string, such as parsing log files or extracting components from URLs.

Find and Replace Mode

Go beyond matching by using the replace tab to apply substitution patterns to your test string. Enter a replacement pattern using standard JavaScript replacement tokens like $1 for the first capture group, $& for the entire match, or $` and $' for text before and after the match. The replaced text appears instantly so you can experiment with different replacement strategies. This is perfect for prototyping text transformations before integrating them into your code.

Flag Controls and Error Handling

Toggle regex flags with a single click to change matching behavior without rewriting your pattern. The global flag finds all occurrences, case-insensitive mode ignores letter casing, multiline mode changes how anchors work, dotAll mode lets the dot match newlines, and Unicode mode enables full Unicode support. If your regex contains a syntax error, a clear message tells you exactly what went wrong so you can fix it immediately. Invalid patterns never crash the tool — they are caught and reported gracefully.

Using Regex Tester in 4 Steps

  1. Enter your regular expression. Type or paste your pattern into the regex input field at the top. The field uses a monospace font and displays your pattern between forward-slash delimiters for clarity. You do not need to include the delimiters yourself — just enter the raw pattern.
  2. Set your flags. Click the flag buttons to toggle options. The g flag is enabled by default so all matches are found. Toggle i for case-insensitive matching, m for multiline mode, s to make the dot match newlines, or u for Unicode mode.
  3. Enter your test string. Paste or type the text you want to test against. The tool immediately highlights all matches within the test string and updates the match count and capture group details.
  4. Review matches and groups. The Matches tab shows your test string with all matches highlighted. Switch to the Capture Groups tab to see a detailed breakdown of each match and its groups. Use the Replace tab to experiment with substitution patterns.
Pro Tip

Watch out for catastrophic backtracking with nested quantifiers like (a+)+ or (.*a){10}. These patterns cause the regex engine to explore an exponential number of paths on non-matching input, freezing your browser or server. Use atomic groups or possessive quantifiers when available.

Common Mistake

Forgetting that the dot (.) matches any character, not a literal period. To match an actual dot (e.g., in domain names or IP addresses), escape it as \.. The pattern example.com also matches "exampleXcom" — use example\.com instead.

Who Uses This Tool

Full-Stack Developer

Elena validates user input forms with regex patterns for emails, phone numbers, and postal codes. She tests each pattern against edge cases in this tool before embedding them in her React components, catching false positives before they reach production.

Data Engineer

Carlos parses unstructured log files from distributed systems. He builds capture group patterns to extract timestamps, error codes, and stack traces from millions of log lines, prototyping each regex here before deploying it in his ETL pipeline.

Security Analyst

Aisha writes detection rules for SIEM platforms. She crafts regex patterns to identify suspicious SQL injection attempts, XSS payloads, and command injection strings, testing them against known attack samples to minimize false negatives.

Understanding Regular Expressions

Regular expressions, often abbreviated as regex or regexp, are one of the most powerful tools available to software developers, data analysts, and system administrators for working with text. A regular expression defines a search pattern using a specialized syntax that can match, locate, and manipulate strings with remarkable precision. The concept originated in the 1950s when mathematician Stephen Cole Kleene formalized the description of regular languages using his mathematical notation. The practical application of these theoretical concepts began in the 1960s when Ken Thompson built regex support into the QED and ed text editors on Unix systems, establishing a tradition of regex integration in command-line tools that continues to this day.

The power of regular expressions lies in their ability to describe complex text patterns concisely. A single regex can express what would otherwise require dozens of lines of procedural string-manipulation code. At the most basic level, a regex is a sequence of literal characters that matches itself — the pattern cat matches the string "cat" wherever it appears. The true power emerges when you combine literals with metacharacters: the dot . matches any single character, square brackets [ ] define a character class, quantifiers like *, +, and ? control repetition, and anchors like ^ and $ pin matches to positions within the string. Parentheses ( ) create capture groups that extract substrings, and the pipe character | provides alternation between choices.

Modern regex engines come in several flavors. PCRE (Perl Compatible Regular Expressions) is one of the most feature-rich and is used by languages like PHP, Python (via its re module, which is PCRE-inspired), and many text editors. JavaScript has its own regex engine that has historically been more limited than PCRE but has been steadily gaining features. Recent ECMAScript specifications added lookbehind assertions, named capture groups, Unicode property escapes, and the dotAll flag, bringing JavaScript much closer to PCRE capability. This tool uses the JavaScript RegExp engine built into your browser, which means the patterns you test here will work identically in your JavaScript code. Other notable flavors include .NET regex, which supports balancing groups, and RE2 from Google, which guarantees linear-time matching by disallowing backreferences.

Common use cases for regular expressions include input validation (verifying that user input matches an expected format such as an email address, phone number, or date), search and replace operations (transforming text by substituting matched patterns with replacement strings), data extraction (pulling structured information out of unstructured text such as log files or web pages), syntax highlighting (identifying keywords, strings, and comments in source code), and web scraping (isolating relevant content from HTML). Whether you are writing a one-line grep command in your terminal or building a complex text processing pipeline, regular expressions are an indispensable skill for anyone who works with text data.

FAQ

What is a regular expression (regex)?

A regular expression is a sequence of characters that defines a search pattern. Regular expressions are used for string matching, searching, and text manipulation in virtually every programming language. They provide a concise and flexible way to identify strings of text such as particular characters, words, or patterns of characters. At their simplest, they match literal text, but they become powerful when combined with metacharacters that represent classes of characters, repetition, positioning, and grouping. Learning regex is a worthwhile investment because the same syntax applies across dozens of languages and tools.

What do regex flags like g, i, m, s, and u mean?

The g (global) flag finds all matches in the string rather than stopping after the first one. The i (case-insensitive) flag causes the engine to ignore the difference between uppercase and lowercase letters during matching. The m (multiline) flag changes the behavior of the ^ and $ anchors so they match the start and end of each line rather than the entire string. The s (dotAll) flag allows the dot metacharacter . to match newline characters, which it does not do by default. The u (unicode) flag enables full Unicode matching so that surrogate pairs and Unicode property escapes work correctly.

How do I match an email address with regex?

A commonly used pattern for basic email validation is [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. This pattern matches a local part containing alphanumeric characters and certain special symbols, followed by an at sign, a domain name with dots and hyphens, and a top-level domain of at least two characters. Keep in mind that the official specification for email addresses (RFC 5322) is extremely complex and allows many unusual formats that simple patterns will not cover. For most practical purposes, a basic pattern combined with a confirmation email is the best validation strategy.

What are capture groups and how do they work?

Capture groups are portions of a regex pattern enclosed in parentheses (). When the pattern matches, the text matched by each group is captured separately and can be referenced by its index number starting from 1. For example, the pattern (\d{4})-(\d{2})-(\d{2}) matching against "2026-03-17" captures "2026" as group 1, "03" as group 2, and "17" as group 3. Named capture groups use the syntax (?<name>...) and let you refer to groups by meaningful names. Non-capturing groups (?:...) group patterns for quantifiers without capturing the matched text.

What is the difference between PCRE and JavaScript regex?

PCRE (Perl Compatible Regular Expressions) is a widely used regex library that supports advanced features like variable-length lookbehind, recursive patterns, atomic groups, possessive quantifiers, conditional patterns, and subroutine calls. JavaScript regex historically lacked many of these features but has been catching up in recent years. Modern JavaScript supports fixed-length and variable-length lookbehind, named capture groups, Unicode property escapes with the u flag, and the dotAll s flag. However, JavaScript still does not support recursive patterns, atomic groups, or possessive quantifiers. This tool uses your browser's built-in JavaScript RegExp engine.

What are lookahead and lookbehind assertions?

Lookahead and lookbehind are zero-width assertions that match a position in the string rather than consuming characters. Positive lookahead (?=...) asserts that the text immediately following the current position matches the given pattern. Negative lookahead (?!...) asserts the opposite — that the following text does not match. Positive lookbehind (?<=...) asserts that the text immediately before the current position matches, and negative lookbehind (?<!...) asserts it does not. These assertions are powerful for matching patterns based on their surrounding context without including that context in the match result.

How do I use backreferences and replacement patterns?

Backreferences allow you to refer to previously captured groups within the same regex using \1, \2, and so on. This is useful for matching repeated content, such as (\w+)\s+\1 to find duplicated words. In replacement strings, you use $1, $2 to insert the value of the corresponding capture group. Named groups can be referenced with $<name>. The token $& inserts the entire match, $` inserts the text before the match, and $' inserts the text after the match. A literal dollar sign is written as $$. These replacement tokens make regex a powerful text transformation tool.

Common Regex Patterns

Memorizing every regex metacharacter is unnecessary when you have a solid library of tested patterns. The following table contains 15 production-ready regular expressions for the most common validation and extraction tasks. Copy any pattern directly into this tool to test it against your own data.

Pattern Name Regex Example Match
Email Address ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ user@example.com
URL (HTTP/HTTPS) https?:\/\/[^\s/$.?#].[^\s]* https://example.com/path
IPv4 Address ^(\d{1,3}\.){3}\d{1,3}$ 192.168.1.1
IPv6 Address ^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$ 2001:0db8:85a3:0000:0000:8a2e:0370:7334
US Phone Number ^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ (555) 123-4567
Date (YYYY-MM-DD) ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ 2025-12-31
Time (24h) ^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$ 14:30:00
Hex Color Code ^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ #ff5733
Strong Password ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&]).{8,}$ P@ssw0rd!
HTML Tag <([a-z]+)([^<]*?)(?:>(.*?)<\/\1>|\/>) <div class="x">...</div>
Username ^[a-zA-Z0-9_-]{3,20}$ cool_user123
Credit Card (Visa) ^4[0-9]{12}(?:[0-9]{3})?$ 4111111111111111
ZIP Code (US) ^\d{5}(-\d{4})?$ 90210 or 90210-1234
MAC Address ^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$ 00:1A:2B:3C:4D:5E
Slug (URL-friendly) ^[a-z0-9]+(?:-[a-z0-9]+)*$ my-blog-post-title

Important note: These patterns cover common cases but are not exhaustive validators. For example, the email regex does not cover every valid email per RFC 5322 (which allows quoted strings and IP addresses in the domain part). Always combine regex validation with additional server-side checks for critical data.

Tools That Pair Well

Related Guides on Our Blog

Citations & Resources