Regex Tester
Test regular expressions in real time with match highlighting.
2 matches found
Why use it
Debug your regex instantly
Real time
Matches highlight as you type. No reloading, no submit buttons.
Capture groups
See each captured group separately with its index and value.
All flags
Full support for g, i, m, s flags from the ECMAScript/JavaScript engine.
No data sent
Your test text never leaves your browser. Ideal for sensitive data.
How it works
Three steps, no hassle
Enter your regex pattern
Type your regular expression in the pattern field. Choose flags: g, i, m, s.
Paste your test text
Enter the text you want to test the pattern against. Matches highlight instantly.
Inspect the results
Review full matches and capture groups. Adjust the pattern until you get the desired result.
FAQ
Got questions?
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern in text. They are a formal language derived from automata theory and formal language theory. With regex you can search, validate, extract, and replace text with complex patterns in a single line of code. They are used in every programming language, text editors, databases, and command-line tools.
The most commonly used patterns include: email (^[\w.+-]+@[\w-]+\.[\w.]+$), URL (https?://[\S]+), phone (\+?[\d\s\-()]{7,15}), ZIP code (/^\d{5}(-\d{4})?$/), ISO date (\d{4}-\d{2}-\d{2}), IPv4 (\b(?:\d{1,3}\.){3}\d{1,3}\b) and alphanumeric only ([a-zA-Z0-9]+). These patterns are starting points — in production they should always be adapted to the exact expected format.
Flags modify the behavior of the pattern: g (global) finds all matches instead of stopping at the first; i (insensitive) ignores case; m (multiline) makes ^ and $ match the start and end of each line, not just the whole text; s (dotAll) makes the dot (.) match newlines too, which it excludes by default. Flags can be combined: /pattern/gim.
Capture groups, defined with parentheses (), let you extract specific parts of a match. For example, /(\d{4})-(\d{2})-(\d{2})/ on '2024-03-15' captures three groups: year, month, and day. Named groups (?<name>pattern) allow access by name rather than numeric index. Non-capturing groups (?:pattern) group without capturing, useful for applying quantifiers without creating a group.
Lookahead and lookbehind are position assertions that check what comes before or after a position without consuming characters. Positive lookahead (?=pattern): matches if followed by pattern. Negative lookahead (?!pattern): matches if NOT followed by pattern. Positive lookbehind (?<=pattern): matches if preceded by pattern. Negative lookbehind (?<!pattern): matches if NOT preceded by pattern. For example, \d+(?= dollars) extracts numbers followed by ' dollars' without including the word.
Regular expression history: from Kleene 1951 to PCRE
Regular expressions were mathematically formulated by Stephen Kleene in 1951 in his paper 'Representation of Events in Nerve Nets and Finite Automata', which introduced algebraic notation for regular languages. The Kleene star operator (*) bears his name. The first practical software implementation was by Ken Thompson in the qed text editor in 1968 for CTSS (Compatible Time-Sharing System). Thompson implemented regex with an efficient NFA (non-deterministic finite automaton) construction that guaranteed O(n) complexity in text size.
PCRE (Perl Compatible Regular Expressions) was created by Philip Hazel in 1997 as a C library reimplementing Perl 5's regex syntax. PCRE added features absent from classic engines: lookahead/lookbehind, named groups, backreferences, and recursion. PCRE became the de facto regex engine for PHP, Apache, nginx, R, and hundreds of other applications. ECMAScript (JavaScript) implements its own engine with similar but distinct semantics, notably lookbehind support added only in ES2018.
In modern web development, regex are essential for form validation in the browser, data extraction in scraping, transformations in build tools like webpack and vite, routing rules in frameworks like Express and Next.js, and advanced search in editors like VS Code. The difference between PCRE and ECMAScript flavors mainly affects: variable-length lookbehind (PCRE supports it, ECMAScript has restrictions), conditional references and recursion (PCRE only), and some escape sequences.