ToolNestr

Regex Tester

Test regular expressions in real-time with match highlighting and groups.

Reviewed by the ToolNestr Editorial Team — July 2026

Flags

Matches

0 matches
Regex matching diagram The pattern \b\w{5}\b is shown above sample text, with arrows pointing to the matched five-letter words "quick" and "jumps" \b \w { 5 } \b The quick brown jumps over the lazy dog quick jumps match index 0 match index 1
Pattern \b\w{5}\b matches five-letter words in the input

How 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

Pattern: \b\w{5}\b
Input: "The quick brown fox jumps over the lazy dog"
Matches: "quick" (index 4), "jumps" (index 26) — two 5-letter words

\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.

Pattern: \d{3}-\d{4}
Input: "Call 555-1234 or 888-5678 for support"
Matches: "555-1234" (index 5), "888-5678" (index 20) — phone number fragments

\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.

Pattern: ^[A-Z].*\.$
Input: "Hello world. this is a test sentence."
Match: "Hello world." — a sentence starting with a capital letter and ending with a period

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

FlagNameEffect
gGlobalFind all matches instead of stopping at the first
iCase-insensitiveIgnore case when matching letters — "A" matches "a"
mMultiline^ and $ match the start/end of each line, not just the string
sDotallThe . metacharacter matches newline characters as well
uUnicodeEnable Unicode features — treat source as a sequence of Unicode code points
yStickyMatch 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.

All tool categories

Developers (24 tools)
🌐 Networking & IP Tools (36 tools)
🧮 Everyday (26 tools)
💪 Health & Fitness (30 tools)
💰 Finance (34 tools)
🔢 Math (23 tools)
📄 PDF Tools (10 tools)
🎨 Creators (12 tools)
⚡ Engineering & Science (24 tools)
⚛️ Physics (48 tools)
🧪 Chemistry (50 tools)
🧬 Biology (50 tools)
🏠 Construction & Home Improvement (105 tools)
👗 Clothing & Garment Tools (68 tools)
🍳 Cooking & Baking (9 tools)
🚗 Automotive (26 tools)
🖼️ Image Tools (13 tools)
🔐 Security & Hash (15 tools)
📝 Text Tools (15 tools)
🔍 SEO Tools (11 tools)
🔄 Converters (69 tools)
🕐 Time & Date (15 tools)
📊 Chart Generators (11 tools)
🕌 Islamic Tools (16 tools)