Input Validation
Validate email addresses, phone numbers, zip codes, credit card numbers, passwords, and other user inputs. Regex can enforce format requirements before data reaches your backend or database.
Write, test, and debug regular expressions with real-time match highlighting — entirely in your browser
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regular expressions are one of the most powerful tools in programming for working with text. They let you search for patterns in strings, validate user input, extract structured data from unstructured text, and perform complex find-and-replace operations — all with a single expression.
Regular expressions are supported in virtually every programming language including JavaScript, Python, Java, C#, Go, Ruby, PHP, and Perl, as well as in command-line tools like grep, sed, and awk. While the syntax varies slightly between flavors, the core concepts — character classes, quantifiers, groups, and anchors — are universal.
The concept of regular expressions originates from formal language theory developed by mathematician Stephen Kleene in the 1950s. Ken Thompson brought them into computing by implementing them in the QED text editor and later in Unix tools. Today, regex is an indispensable skill for developers, data scientists, system administrators, and anyone who works with text data at scale.
At its core, a regex engine reads a pattern character by character and tries to match it against an input string. The engine walks through the string one position at a time, attempting to find a sequence of characters that satisfies the entire pattern. If a match attempt fails at any point, the engine backtracks and tries the next starting position.
Literal characters in a pattern match themselves. The pattern cat matches the exact string "cat" within any text. Special characters (called metacharacters) have special meanings: . matches any character, \d matches any digit, and \w matches any word character (letter, digit, or underscore).
Quantifiers specify how many times a character or group should repeat. * means zero or more, + means one or more, ? means zero or one, and {n,m} means between n and m times. By default, quantifiers are greedy — they match as much as possible. Adding ? after a quantifier makes it lazy, matching as little as possible.
Parentheses () create capture groups that let you extract specific parts of a match. For example, (\d{4})-(\d{2})-(\d{2}) applied to "2024-03-15" captures "2024", "03", and "15" as separate groups. Named groups like (?<year>\d{4}) make your patterns more readable and maintainable.
^ asserts the position at the start of the string (or line in multiline mode), while $ asserts the end. \b marks a word boundary — the position between a word character and a non-word character. These anchors don't match characters themselves but rather positions in the string.
Validate email addresses, phone numbers, zip codes, credit card numbers, passwords, and other user inputs. Regex can enforce format requirements before data reaches your backend or database.
Find and extract structured data from unstructured text — URLs from web pages, dates from documents, error codes from log files, or specific fields from CSV and configuration files.
Perform sophisticated text transformations — reformat dates, rename variables across a codebase, clean up whitespace, normalize data formats, or restructure text with capture group back-references.
Split text into meaningful tokens for lexical analysis, syntax highlighting, Markdown processing, template engines, or any application that needs to understand the structure of text.
Flags (also called modifiers) change how the regex engine interprets and applies a pattern. In JavaScript, flags are appended after the closing delimiter of the regex literal (/pattern/flags) or passed as the second argument to new RegExp(pattern, flags).
| Flag | Name | Description |
|---|---|---|
g |
Global | Find all matches in the string, not just the first. Without this flag, the regex stops after the first match. |
i |
Case-insensitive | Makes the pattern match regardless of letter case. /abc/i matches "ABC", "Abc", "aBc", etc. |
m |
Multiline | Changes ^ and $ to match the start/end of each line, not just the entire string. Essential for line-by-line matching. |
s |
DotAll | Makes . match any character including newlines (\n, \r). By default, . does not match newline characters. |
u |
Unicode | Enables full Unicode matching. Treats the pattern and string as Unicode code points. Required for matching emoji and supplementary characters correctly. |
y |
Sticky | Matches only at the position indicated by lastIndex. Unlike global, it will not scan ahead — the match must start exactly at the expected position. |
$1, $2 for numbered groups, $<name> for named groups, $& for the full match, and $` / $' for pre/post-match text.A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regular expressions are used for pattern matching within strings — finding, extracting, replacing, or validating text. They are supported in virtually every programming language including JavaScript, Python, Java, C#, Go, and Ruby, as well as in command-line tools like grep, sed, and awk.
Yes. This tool processes everything entirely in your browser using JavaScript. Your patterns and test strings are never transmitted to any server. You can verify this by checking the browser's network tab — no requests are made when you test a pattern. The tool works offline after the initial page load.
This tool supports all standard JavaScript regex flags: g (global — find all matches), i (case-insensitive matching), m (multiline — ^ and $ match line boundaries), s (dotAll — dot matches newlines), u (unicode — full Unicode support), and y (sticky — match from lastIndex only).
Capture groups are portions of a regex pattern enclosed in parentheses (). They let you extract specific parts of a match. For example, the pattern (\d{4})-(\d{2})-(\d{2}) applied to "2024-03-15" captures the year, month, and day as separate groups. Named groups use the syntax (?<name>...) for clearer code. This tool displays all capture groups for each match.
Greedy quantifiers (*, +, {n,m}) match as much text as possible, while lazy quantifiers (*?, +?, {n,m}?) match as little as possible. For example, given the text "<b>bold</b>", the greedy pattern <.+> matches the entire string "<b>bold</b>", but the lazy pattern <.+?> matches just "<b>" and then "</b>" separately.
While the core regex syntax is similar across languages, there are differences in supported features. For example, JavaScript does not support possessive quantifiers (++, *+) or atomic groups ((?>...)), which languages like Java and .NET do. Lookahead and lookbehind support also varies — JavaScript added lookbehind in ES2018, but older browsers may not support it. This tool uses the JavaScript regex engine built into your browser.
In the replace field, you can use special replacement patterns. $1, $2, etc. insert the text captured by the corresponding numbered group. $<name> inserts a named group's capture. $& inserts the entire match. $` inserts the text before the match, and $' inserts the text after. $$ inserts a literal dollar sign. These patterns follow the JavaScript String.replace() specification.