// text

Regex Tester.

Live JavaScript regex tester with flags, capture groups, named groups, and a match list.

Client-sideNo uploadLive match

Test text

Matches

Highlighted

How regex testing works.

Enter a regular expression pattern and test string, and this tool highlights every match in real time. Matches are shown in the highlighted section with <mark> tags, and each match is listed individually with its index and captured groups. This is the fastest way to verify a regex works before using it in code.

The tool uses JavaScript's native RegExp engine, so patterns behave exactly as they do in Node.js or browser JavaScript. If you're using regex in Python, Go, or PCRE, the syntax may differ — JavaScript uses its own flavor with some differences in lookaheads and backreferences.

Common flags.

g (global) — find all matches, not just the first. Without g, only the first match is shown. i (case-insensitive) — ignore uppercase/lowercase differences. m (multiline) — ^ and $ match line boundaries, not just string boundaries. s (dotAll) — . matches newline characters. u (unicode) — enable full Unicode support for emoji and special characters.

Combine flags by typing them together: gi for global case-insensitive, gim for global case-insensitive multiline. The flags field accepts any combination of standard JavaScript regex flags.

Tips for writing better regex.

Start simple. Write the simplest pattern that matches, then add complexity. Start with foo before writing ^foo(?:bar|baz)+$. Test each addition against multiple inputs.

Use non-greedy quantifiers. .*? matches as little as possible; .* matches as much as possible. Non-greedy is usually what you want when extracting specific text between delimiters.

Test edge cases. After your pattern works on the happy path, test it against empty strings, strings with no matches, strings with special characters, and very long strings. This tool makes it easy to try multiple inputs quickly.

Essential regex syntax.

Regular expressions use a compact syntax to describe text patterns. . matches any single character. \d matches a digit, \w matches a word character (letter, digit, underscore), and \s matches whitespace. Capitalized versions (\D, \W, \S) match the opposite. Quantifiers control repetition: * means zero or more, + means one or more, ? means zero or one, and {n} means exactly n times. You can also use ranges like {2,5} for two to five repetitions.

Anchors specify position: ^ matches the start of the string (or line in multiline mode), and $ matches the end. Without anchors, a pattern can match anywhere in the string. Character classes like [aeiou] match any vowel, and ranges like [a-z] match any lowercase letter. The | operator alternates between patterns: cat|dog matches either word. Grouping with parentheses (...) captures matched text and enables alternation within groups.

Common regex patterns.

Email validation: /^[^\s@]+@[^\s@]+\.[^\s@]+$/ — matches basic email format. URL matching: /https?:\/\/[^\s]+/ — captures HTTP and HTTPS URLs. Date format: /\d4-\d2-\d2/ — matches YYYY-MM-DD. IPv4 address: /\b\d3\.\d3\.\d3\.\d3\b/. Hex color: /#([0-9a-fA-F]3)2\b/. These patterns are starting points — real-world validation often requires more nuance.

Extracting data: Use capturing groups to pull specific parts of a match. The pattern /(\d4)-(\d2)-(\d2)/ on 2024-05-21 captures year, month, and day as separate groups. Lookaheads: /\d+(?=px)/ matches numbers followed by px without including the px in the match. Lookbehinds: /(?<=\$)\d+/ matches numbers preceded by a dollar sign.

Debugging regex patterns.

When a regex doesn't match what you expect, start by simplifying. Remove optional parts and test the core pattern first. Add complexity back one piece at a time, testing after each addition. Use this tool's highlighted output to see exactly where the pattern matches and where it doesn't. Pay attention to boundary conditions — does the pattern match at the start, end, or middle of the string?

Common mistakes include forgetting to escape special characters (. matches any character; use \. to match a literal dot), using greedy quantifiers when you need non-greedy ones, and not accounting for multiline content. The s (dotAll) flag makes . match newlines, which is often needed for multiline text. Test with multiple inputs including edge cases — empty strings, strings with no matches, and strings with special characters.

FAQ

What's the best online regex tester that runs in the browser?

regex101.com (flagship), regexr.com (great for learning with cheatsheet), and debuggex.com (visual railroad diagrams) — all run client-side for most operations.

How do I test a regex with multiple flags and replace behavior?

regex101.com lets you set flags (g, i, m, s, u) and switch between Match and Replace modes; great for previewing substitutions before using in code.

Why does my regex work in regex101 but not in JavaScript?

Different regex flavors — regex101 defaults to PCRE; switch the flavor dropdown to 'JavaScript' to match JS's limited lookbehind, no atomic groups, no `\A\z` anchors.

How do I escape special characters in a regex?

Prefix each special char with `\`: `.`, `*`, `+`, `?`, `(`, `)`, `[`, `]`, `{`, `}`, `^`, `$`, `|`, `\`. Most languages have a `re.escape()` / `RegExp.escape()` utility.

Can I save and share regex patterns with teammates?

regex101.com generates a permanent URL with your pattern, flags, and test strings — just share the link; regexr.com also supports saved patterns via account.