Free Regex Tester -- Test Regular Expressions Online

Test and debug regular expressions with real-time match highlighting

Write a regex pattern, paste your test string, and see every match highlighted in real time. Includes capture groups, replace mode, and pattern explanation. Everything runs in your browser -- nothing is sent anywhere.

/ /
Replace with
Matches 0
Groups 0
Steps --
Time --
Replace result
Match details
#MatchIndexGroups
Pattern explanation
Enter a pattern above to see its breakdown.

How to Use This Regex Tester

  1. Enter a pattern in the regex field -- for example, \d+ to match digits.
  2. Toggle flags by clicking the pill buttons (g, i, m, s) to the right of the pattern.
  3. Paste or type text in the Test String area.
  4. See matches highlighted instantly with alternating colors for adjacent matches.
  5. Switch to Replace mode to enter a substitution string and preview the result live.

Use the preset buttons to load common patterns (email, URL, phone, etc.) with example text. The match details table shows each match's text, position index, and capture groups. The pattern explanation panel breaks down your regex token by token.

About Regular Expressions

A regular expression (regex) is a pattern that describes a set of strings. It is used in programming, text editors, and command-line tools to search, match, validate, and replace text.

Regex syntax uses literal characters (which match themselves) combined with special metacharacters that define rules:

  • \d -- matches any digit (0-9)
  • \w -- matches any word character (letters, digits, underscore)
  • \s -- matches whitespace (space, tab, newline)
  • . -- matches any character except newline (unless the s flag is set)
  • + -- one or more of the preceding element
  • * -- zero or more of the preceding element
  • ? -- zero or one (makes the preceding element optional)
  • {n,m} -- between n and m repetitions
  • ^ and $ -- start and end of string (or line, with the m flag)
  • [abc] -- character class: matches a, b, or c
  • (...) -- capturing group
  • | -- alternation (OR)

Common Patterns

Use CasePatternExample Match
Digits only^\d+$"12345"
Email (simplified)[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"[email protected]"
US phone number\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}"(555) 123-4567"
URLhttps?://[^\s]+"https://example.com/page"
Date (YYYY-MM-DD)\d{4}-\d{2}-\d{2}"2025-01-15"
Hex color#[0-9A-Fa-f]{3,6}\b"#00d4aa"
IPv4 address\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"192.168.1.1"
Whole word\bcat\b"cat" (not "cats")

Greedy vs. Lazy Matching

By default, quantifiers (*, +, {n,m}) are greedy: they match as much text as possible. Adding ? after a quantifier makes it lazy -- it matches as little as possible.

Example: Given the string <b>bold</b>:

  • <.*> (greedy) matches <b>bold</b> -- the entire string
  • <.*?> (lazy) matches <b> -- the shortest match

Flags Explained

FlagNameEffect
gGlobalFind all matches, not just the first
iCase Insensitive/abc/i matches "ABC", "aBc", etc.
mMultiline^ and $ match start/end of each line, not just the whole string
sDotAll. matches newline characters too

Common Mistakes

  • Forgetting to escape special characters: . matches any character. To match a literal dot, use \.
  • Using * when you need +: \d* matches empty strings. Use \d+ when you need at least one digit.
  • Missing the g flag: Without it, only the first match is returned.
  • Over-matching with .*: Greedy .* swallows more text than intended. Try .*? or be more specific.
  • Anchors in multiline text: ^ and $ match string boundaries by default. Enable the m flag if you need per-line matching.

Frequently Asked Questions

What is a regular expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. It is used to match, find, or replace text in strings. For example, the pattern \d+ matches one or more digits, so it would match "42" in the string "Room 42".

How do I test a regex pattern?

Enter your regex pattern in the Pattern field, paste or type your test string below, and matches are highlighted instantly. Enable flags like global (g), case-insensitive (i), or multiline (m) as needed. Capture groups are shown separately below the highlighted text.

What does the global (g) flag do?

Without the global flag, a regex stops after the first match. With the g flag enabled, it finds all matches in the entire string. For example, /\d+/ matches only the first number, while /\d+/g matches every number in the text.

What is the difference between * and + in regex?

The * quantifier matches zero or more occurrences, while + matches one or more. For example, ab*c matches "ac", "abc", and "abbc". But ab+c matches "abc" and "abbc" -- not "ac", because + requires at least one "b".

Is my data sent to a server?

No. This regex tester runs entirely in your browser using JavaScript. Your pattern and test string never leave your device. Nothing is stored or transmitted.

What regex flags are supported?

This tester supports the standard JavaScript regex flags: g (global), i (case-insensitive), m (multiline), s (dotAll -- dot matches newline).

How do capture groups work?

Parentheses create capture groups that extract parts of a match. For example, the pattern (\d{3})-(\d{4}) applied to "555-1234" captures "555" as group 1 and "1234" as group 2. Named groups use the syntax (?<name>...) for readability.

What is a non-capturing group?

A non-capturing group (?:...) groups characters for quantifiers or alternation without storing the match. For example, (?:Mr|Mrs) Smith matches "Mr Smith" or "Mrs Smith" but does not capture the title as a separate group.

How do I match a literal dot or special character?

Special characters like . * + ? ^ $ { } [ ] ( ) | \ have meaning in regex. To match them literally, escape with a backslash. For example, \. matches a literal period, \$ matches a dollar sign, and \( matches a literal parenthesis.

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +) match as much text as possible. Lazy quantifiers (*?, +?) match as little as possible. For example, given <b>bold</b>, the greedy <.*> matches the entire string, while the lazy <.*?> matches only <b>.

What This Tool Does Not Do

  • It does not support every regex engine -- this tester uses JavaScript's built-in regex engine. Some features (like \p{L} Unicode properties without the u flag, or recursive patterns) are engine-specific.
  • It does not save your patterns or test strings -- everything is cleared when you refresh the page.
  • It does not validate regex correctness beyond syntax -- a valid pattern may not do what you intend.

Related Tools

Privacy & Limitations

  • All calculations run entirely in your browser -- nothing is sent to any server.
  • Results are computed locally and should be verified for critical applications.

Related Tools

View all tools

Regex Tester FAQ

What is a regular expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. It is used to match, find, or replace text in strings. For example, the pattern \d+ matches one or more digits, so it would match '42' in the string 'Room 42'.

How do I test a regex pattern?

Enter your regex pattern in the Pattern field, paste or type your test string below, and matches are highlighted instantly. Enable flags like global (g), case-insensitive (i), or multiline (m) as needed. Capture groups are shown separately below the highlighted text.

What does the global (g) flag do?

Without the global flag, a regex stops after the first match. With the g flag enabled, it finds all matches in the entire string. For example, /\d+/ matches only the first number, while /\d+/g matches every number in the text.

What is the difference between * and + in regex?

The * quantifier matches zero or more occurrences, while + matches one or more. For example, ab*c matches 'ac', 'abc', and 'abbc'. But ab+c matches 'abc' and 'abbc' -- not 'ac', because + requires at least one 'b'.

Is my data sent to a server?

No. This regex tester runs entirely in your browser using JavaScript. Your pattern and test string never leave your device. Nothing is stored or transmitted.

What regex flags are supported?

This tester supports the standard JavaScript regex flags: g (global -- find all matches), i (case-insensitive), m (multiline -- ^ and $ match line boundaries), s (dotAll -- dot matches newline), and u (unicode -- full Unicode support).

How do capture groups work in regex?

Parentheses create capture groups that extract parts of a match. For example, the pattern (\d{3})-(\d{4}) applied to '555-1234' captures '555' as group 1 and '1234' as group 2. Named groups use the syntax (?<name>...) for readability.

What is a non-capturing group?

A non-capturing group (?:...) groups characters for quantifiers or alternation without capturing the match. For example, (?:Mr|Mrs) Smith matches 'Mr Smith' or 'Mrs Smith' but does not store the title as a separate group. This is useful when you need grouping but not extraction.

How do I match a literal dot or special character?

Special characters like . * + ? ^ $ { } [ ] ( ) | \ have meaning in regex. To match them literally, escape with a backslash. For example, \. matches a literal period, \$ matches a dollar sign, and \( matches a literal parenthesis.

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +, {n,m}) match as much text as possible. Lazy quantifiers (*?, +?, {n,m}?) match as little as possible. For example, given '<b>bold</b>', the greedy pattern <.*> matches the entire string, while the lazy pattern <.*?> matches only '<b>'.

Request a New Tool
Improve This Tool