Regex Tester
Test regular expressions in real-time with match highlighting and groups.
Reviewed by the ToolNestr Editorial Team — July 2026
Matches
0 matches\b\w{5}\b matches five-letter words in the inputHow regex patterns work
Regular expressions are patterns used to match character combinations in strings. A pattern consists of literal characters and metacharacters that describe what to search for. Literal characters like a, 1, or hello match themselves exactly — they are the simplest form of a regex pattern. Metacharacters add matching power: . matches any single character, \d matches any digit, \w matches any word character (letter, digit, or underscore), and \s matches any whitespace character (space, tab, newline).
Anchors let you specify position within the string: ^ matches the start of a string (or line with the m flag), $ matches the end, and \b matches a word boundary — the position between a word character and a non-word character. Quantifiers control repetition: + means one or more, * means zero or more, ? means zero or one, and {n,m} specifies an exact range. Combining these building blocks lets you express a wide variety of text patterns concisely.
Groups and character classes add further precision. A character class like [aeiou] matches any single vowel, while [^aeiou] matches any non-vowel. Parentheses (...) create capturing groups that extract the matched portion for later use, and (?:...) creates non-capturing groups that group without capturing. Alternation with | lets you match one of several patterns — cat|dog matches either "cat" or "dog".
Worked examples
\b\w{5}\b\b matches a word boundary, \w{5} matches exactly five word characters, and the second \b ensures the match ends at a boundary. This finds all five-letter words in the text.
\d{3}-\d{4}\d{3} matches exactly three digits, the hyphen is a literal character, and \d{4} matches exactly four digits. This pattern matches phone number trailing portions in the format XXX-XXXX.
^[A-Z].*\.$The ^ anchor requires the match to start at the beginning of the string, [A-Z] matches an uppercase letter, .* matches any characters in between, and \.$ requires the string to end with a literal period.
Use cases for regex
Form validation
Validate user input like email addresses, phone numbers, ZIP codes, and passwords on the client side before submission. Regex provides instant feedback without a round trip to the server.
Log parsing
Extract structured data from unstructured log files — timestamps, IP addresses, HTTP status codes, error messages, and stack traces. Regex is the standard tool for ad-hoc log analysis.
Find and replace
Transform text across large codebases or documents. Rename variables, normalize date formats, fix whitespace issues, or restructure data using regex capture groups in the replacement pattern.
Data extraction
Scrape or extract specific data from HTML, JSON, CSV, or plain text. Extract all URLs from a page, pull out phone numbers from a document, or grab specific fields from structured text.
Tips for writing robust regex
Beware of catastrophic backtracking
Nested quantifiers like (a+)+b can cause exponential backtracking when applied to strings that nearly match but fail. On input like "aaaaaaaaac", the engine tries every possible way to split the "a"s between the inner and outer + before giving up. This can freeze your browser or crash your application. Use atomic groups (?>...) or possessive quantifiers where supported, or rewrite the pattern to be unambiguous.
Test edge cases
Always test your regex against edge cases: empty strings, very long strings, strings with special characters, strings that almost match but fail at the last character, and strings with multiple possible matches. What looks correct intuitively may fail on unexpected input. Keep a small set of test cases that exercise boundaries.
Think in terms of delimiters
When constructing a regex pattern mentally, imagine it between two forward slashes /pattern/flags. The pattern itself contains only the matching logic — no quotes, no escape sequences for the host language. Backslashes in the pattern are part of the regex syntax, not JavaScript string escapes. Use raw strings or double-escape when writing regex in code strings.
Start simple and iterate
Begin with the simplest pattern that captures your data, then add constraints incrementally. Test each addition against all your test cases. Complex regex built in one pass is almost always wrong. Build up from a solid foundation and verify each step.
Regular expression flag reference
| Flag | Name | Effect |
|---|---|---|
| g | Global | Find all matches instead of stopping at the first |
| i | Case-insensitive | Ignore case when matching letters — "A" matches "a" |
| m | Multiline | ^ and $ match the start/end of each line, not just the string |
| s | Dotall | The . metacharacter matches newline characters as well |
| u | Unicode | Enable Unicode features — treat source as a sequence of Unicode code points |
| y | Sticky | Match only from the lastIndex position (used with global for incremental scanning) |
Related tools
Frequently asked questions
What regex engine is used?
JavaScript's built-in RegExp engine — matches ECMAScript regex syntax.
What flags are available?
g (global), i (case-insensitive), m (multiline), s (dotall), u (unicode), y (sticky).
Does it support lookahead/lookbehind?
Yes — JS supports both positive/negative lookahead (?=) and lookbehind (?<=).
Can I test against multiple lines?
Yes — paste multi-line text and use the m flag for ^/$ per-line matching.