Regex Tester
Test regular expressions in real time with instant match highlighting, capture groups, and index positions.
No matches yet.
Regex Cheat Sheet
Character Classes
| . | Any character (except newline) |
| \d | Digit [0-9] |
| \D | Non-digit |
| \w | Word char [A-Za-z0-9_] |
| \W | Non-word char |
| \s | Whitespace |
| \S | Non-whitespace |
| [abc] | Any of a, b, or c |
| [^abc] | Not a, b, or c |
| [a-z] | Range a to z |
Quantifiers
| * | 0 or more |
| + | 1 or more |
| ? | 0 or 1 |
| {n} | Exactly n |
| {n,} | n or more |
| {n,m} | Between n and m |
| *? | Lazy 0 or more |
| +? | Lazy 1 or more |
Anchors
| ^ | Start of string / line |
| $ | End of string / line |
| \b | Word boundary |
| \B | Non-word boundary |
Groups & Lookaround
| (abc) | Capturing group |
| (?:abc) | Non-capturing group |
| (?=abc) | Positive lookahead |
| (?!abc) | Negative lookahead |
| (?<=abc) | Positive lookbehind |
| (?<!abc) | Negative lookbehind |
What Are Regular Expressions and How Do They Work?
Regular expressions — commonly abbreviated as regex or regexp — are sequences of characters that define search patterns. Originally rooted in formal language theory developed by mathematician Stephen Cole Kleene in the 1950s, regex has become one of the most versatile and widely used tools in modern software development. Every major programming language, from JavaScript and Python to Java and Go, ships with built-in regex support, and virtually every text editor offers regex-based search and replace.
At its core, a regular expression is a miniature domain-specific language for describing text patterns. Instead of searching for a fixed string like "hello", you can write a pattern such as \b[A-Za-z]+\b to match every word in a document, or \d{4}-\d{2}-\d{2} to find dates in ISO 8601 format. This flexibility makes regex invaluable for tasks that involve structured or semi-structured text.
Basic Syntax Building Blocks
Character classes let you match categories of characters. \d matches any digit, \w matches word characters (letters, digits, and underscores), and \s matches whitespace. You can also define custom sets with square brackets: [aeiou] matches any vowel, while [^0-9] matches anything that is not a digit.
Quantifiers control how many times a token must appear. The asterisk * means "zero or more," the plus sign + means "one or more," and the question mark ? means "zero or one." Curly braces give precise control: {3} means exactly three, {2,5} means between two and five. Appending ? to any quantifier makes it lazy, matching as few characters as possible instead of as many.
Anchors pin your match to a position rather than consuming characters. The caret ^ asserts the start of a line (when the multiline flag is set), while $ asserts the end. The word-boundary anchor \b ensures a match occurs at the edge of a word, which is essential for avoiding partial matches — for example, matching cat without also matching concatenate.
Groups and capturing are what make regex truly powerful for extraction. Wrapping part of a pattern in parentheses (…) creates a capturing group whose matched text you can reference later. Named groups like (?<year>\d{4}) add readability. Non-capturing groups (?:…) let you apply quantifiers to sub-patterns without storing the match. Lookaheads (?=…) and lookbehinds (?<=…) assert that a pattern exists before or after the current position without including it in the match, enabling sophisticated contextual searches.
How This Tool Works
This free online regex tester executes your pattern against the test string entirely in your browser using JavaScript's native RegExp engine — nothing is sent to a server. As you type, the tool compiles the regex, iterates through all matches, and renders highlighted results in real time. Each match is displayed with its full text, character index in the original string, and any captured groups. If your pattern contains a syntax error, you will see a clear red-bordered warning instead of a cryptic console error.
Common Patterns
Some patterns appear in nearly every developer's toolkit. Email validation (simplified: [\w.-]+@[\w-]+\.[\w.]{2,}), URL detection, phone number extraction, date parsing, and IP address matching are so common that we have included one-click preset buttons above. These presets load both the pattern and a sample test string so you can see matches immediately and tweak them to your needs.
Use Cases for Regular Expressions
Form validation: Regex is the backbone of client-side and server-side input validation. Whether you are checking that an email address is well-formed or that a password meets complexity requirements, a carefully crafted pattern can enforce rules in a single line of code.
Data extraction: Need to pull prices from a web page, extract timestamps from log files, or harvest links from HTML? Regex captures let you zero in on the data you care about and ignore the rest.
Search and replace: Every code editor's find-and-replace dialog supports regex. Renaming variables across a codebase, reformatting dates, or normalizing whitespace is fast and precise with pattern-based replacement.
Log parsing: System administrators and DevOps engineers rely on regex to filter and analyze massive log files. Tools like grep, awk, and sed are built around regex, and modern observability platforms use regex patterns for log-based alerting.
Web scraping: While dedicated HTML parsers are preferred for complex pages, regex remains a pragmatic choice for extracting simple patterns from API responses, CSV exports, or plaintext feeds.
Frequently Asked Questions
What does the g flag do? The global flag tells the regex engine to find all matches in the string instead of stopping after the first one. Without g, methods like String.prototype.match() return only the first match along with its capture groups.
How do capture groups work? Anything enclosed in parentheses (…) forms a capture group. After a match, you can access each group by its index (starting at 1) or by name if you used (?<name>…). Captures are essential for extracting sub-parts of a match — for example, pulling the domain from an email address.
What's the difference between * and +? Both are quantifiers, but * matches zero or more occurrences of the preceding token, while + requires at least one. This distinction matters: the pattern a* will match an empty string, whereas a+ will not.
This regex tester is completely free and runs entirely in your browser — no sign-up, no data collection, no server round-trips. Bookmark it, share it with your team, and make regex a little less intimidating.