ToolSpotAI

Regex Tester

Test regular expressions with live matching, highlighting, capture groups, find & replace, and a quick reference cheat sheet.

Developer

Regular expression

//g

Quick presets

Test string

4 matches

Highlighted matches

Contact us at hello@example.com or support@company.org. Also try test@domain.co.uk and admin@site.io.

Match details (4)

#1
hello@example.comindex 14
$1: hello$2: example$3: com
#2
support@company.orgindex 35
$1: support$2: company$3: org
#3
test@domain.coindex 65
$1: test$2: domain$3: co
#4
admin@site.ioindex 87
$1: admin$2: site$3: io

Quick reference

.Any character
\dDigit [0-9]
\wWord char [a-zA-Z0-9_]
\sWhitespace
^Start of line
$End of line
*0 or more
+1 or more
?0 or 1
{n}Exactly n times
{n,m}n to m times
[abc]Character class
[^abc]Negated class
(โ€ฆ)Capture group
(?:โ€ฆ)Non-capturing group
a|bAlternation

All regex processing is done locally in your browser using the JavaScript RegExp engine. No data is sent to any server.

Advertisement

What is Regex Tester?

A regex tester lets you write and test regular expressions against sample text with instant visual feedback. Regular expressions are essential for text processing, data validation, search and replace, and string parsing in every programming language. Our tester provides live matching with highlighted results, detailed match information including capture groups and named groups, find & replace with backreferences, flag toggles (g, i, m, s, u), common pattern presets, and a quick reference cheat sheet โ€” all running locally in your browser.

How It Works

Enter a regex pattern and test string. Matches are highlighted in real time as you type. Each match shows its position, full match text, and any capture groups. Toggle flags to change matching behaviour. Enable Find & Replace to test substitution patterns with $1, $2 group references. Use the presets for common patterns like email, URL, phone number, and IP address.

Formula

Regex syntax: . (any char), \d (digit), \w (word char), \s (whitespace), ^ (start), $ (end), * (0+), + (1+), ? (0 or 1), {n,m} (n to m), [abc] (char class), (โ€ฆ) (group), a|b (alternation)

Formula Explained

Regular expressions are compiled into finite state machines that process input character by character. The engine tries to match the pattern at each position in the string. Quantifiers (*, +, ?) control how many times a sub-pattern can repeat. Character classes [abc] match any single character in the set. Groups (โ€ฆ) capture matched text for extraction or backreferencing. The JavaScript regex engine uses backtracking for complex patterns.

Example

Pattern: ([a-zA-Z]+)@([a-zA-Z]+)\.([a-z]{2,}) Flags: g Test: "Contact hello@example.com or support@company.org" Match 1: hello@example.com (index 8) $1: hello, $2: example, $3: com Match 2: support@company.org (index 28) $1: support, $2: company, $3: org Replace with "$1@newdomain.com": "Contact hello@newdomain.com or support@newdomain.com"

Tips & Best Practices

  • โœ“Start simple and build up complexity โ€” test each part of your pattern separately.
  • โœ“Use the g flag to find all matches, not just the first one.
  • โœ“Escape special characters with \ when you want to match them literally.
  • โœ“Use non-capturing groups (?:โ€ฆ) when you do not need to extract the match.
  • โœ“Test edge cases: empty strings, strings with only whitespace, and strings with special characters.

Common Use Cases

  • โ€ขValidating email addresses, phone numbers, and URLs
  • โ€ขExtracting data from structured text using capture groups
  • โ€ขTesting find & replace patterns before using them in code
  • โ€ขLearning regular expression syntax with immediate feedback
  • โ€ขDebugging complex regex patterns with detailed match information

Frequently Asked Questions

A regular expression (regex) is a sequence of characters that defines a search pattern. It is used to find, match, and manipulate text. For example, the pattern \d{3}-\d{3}-\d{4} matches US phone numbers like 555-123-4567. Regex is supported in virtually every programming language.

g (global): find all matches, not just the first. i (case insensitive): A matches a. m (multiline): ^ and $ match line boundaries. s (dotall): . matches newline characters. u (unicode): enables full Unicode matching. You can combine multiple flags.

Parentheses () create capture groups that extract parts of a match. In the pattern (\w+)@(\w+)\.(\w+), group $1 captures the username, $2 the domain, and $3 the TLD from an email. Use $1, $2 etc. in replacement strings to reference captured groups.

* matches zero or more of the preceding element (ab*c matches "ac", "abc", "abbc"). + matches one or more (ab+c matches "abc", "abbc" but NOT "ac"). Use *? and +? for lazy (non-greedy) matching.

Yes. This tester uses the JavaScript RegExp engine, which is what runs in all browsers and Node.js. Patterns that work here will work in your JavaScript code. Note that some regex features from other languages (like lookbehinds in older browsers) may have limited support.

Related tools