Regex Tester

Test regular expressions against a string and see all matches highlighted

Try an example

Pattern

//g

Test string

Runs locally Β· Safe to paste secrets

What is a Regular Expression?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regex testers let you write a pattern, run it against sample text, and see all matches highlighted in real time. The concept dates back to mathematician Stephen Kleene's work on regular languages in the 1950s, and Ken Thompson built the first regex engine into the QED text editor in 1968.

A regex engine reads a pattern left to right, consuming input characters as it tries to match. It uses backtracking when a partial match fails: the engine steps back and tries alternative paths through the pattern. Some engines (like RE2 used in Go) avoid backtracking entirely by converting patterns to deterministic finite automata (DFA), which guarantees linear-time matching at the cost of not supporting features like back-references.

Regex syntax is standardized loosely. PCRE (Perl Compatible Regular Expressions) is the most common flavor, supported by PHP, Python's re module, and JavaScript with minor differences. POSIX defines a more limited syntax used by grep and sed. The differences matter when porting patterns between languages: a lookahead that works in JavaScript may not compile at all in Go's RE2 engine.

Why Use an Online Regex Tester?

Writing regex in a code file means saving, running, and inspecting output each time you adjust the pattern. A browser-based regex tester closes that feedback loop to zero: you type, you see matches.

⚑
Real-time match highlighting
Every keystroke updates the match results instantly. You see which parts of the text match, which capture groups are populated, and exactly where each match starts and ends. No compile-run-debug cycle.
πŸ”’
Privacy-first processing
Pattern matching runs in your browser using the JavaScript RegExp engine. No text or patterns are sent to a server. This matters when testing against log files, customer data, or API responses that contain sensitive information.
πŸ”
Visual match inspection
Matches are highlighted inline with their positions and capture group values displayed. Seeing matches visually makes it easier to catch off-by-one errors in quantifiers or missing anchors.
🌐
No login or install required
Works on any device with a modern browser. No account, no extension, no IDE plugin. Open the page, paste your pattern and text, and start testing.

Regex Tester Use Cases

Frontend Input Validation
Build and verify patterns for email, phone number, or credit card fields before embedding them in HTML5 pattern attributes or JavaScript validation logic.
Backend Log Parsing
Write regex patterns that extract timestamps, error codes, or IP addresses from application logs. Test against real log samples to confirm the pattern captures the right groups.
DevOps & Infrastructure
Debug regex used in Nginx location blocks, Apache rewrite rules, or Prometheus alerting rules. A wrong pattern in a server config can break routing or miss alerts entirely.
QA & Test Automation
Validate that response bodies or HTML output match expected patterns in end-to-end test assertions. Pre-test the regex here before committing it to your test suite.
Data Extraction Pipelines
Prototype patterns for extracting structured fields from unstructured text: scraping product prices, parsing CSV edge cases, or pulling metadata from email headers.
Learning Regular Expressions
Experiment with metacharacters, quantifiers, and groups against sample strings. Immediate visual feedback makes regex syntax easier to learn than reading documentation alone.

Regex Syntax Quick Reference

The table below covers the most-used regex tokens. These work across JavaScript, Python, Go, PHP, and most PCRE-compatible engines. Language-specific extensions (like Python's conditional patterns or JavaScript's named groups with \k syntax) are noted in the code examples section.

PatternNameDescription
.Any characterMatches any single character except newline (unless s flag is set)
\dDigitMatches [0-9]
\wWord characterMatches [a-zA-Z0-9_]
\sWhitespaceMatches space, tab, newline, carriage return, form feed
\bWord boundaryMatches the position between a word character and a non-word character
^Start of string/lineMatches the start of the input; with m flag, matches start of each line
$End of string/lineMatches the end of the input; with m flag, matches end of each line
*Zero or moreMatches the preceding token 0 or more times (greedy)
+One or moreMatches the preceding token 1 or more times (greedy)
?OptionalMatches the preceding token 0 or 1 time
{n,m}Quantifier rangeMatches the preceding token between n and m times
()Capturing groupGroups tokens and captures the matched text for back-references
(?:)Non-capturing groupGroups tokens without capturing the matched text
(?=)Positive lookaheadMatches a position followed by the given pattern, without consuming it
(?<=)Positive lookbehindMatches a position preceded by the given pattern, without consuming it
[abc]Character classMatches any one of the characters inside the brackets
[^abc]Negated classMatches any character not inside the brackets
|AlternationMatches the expression before or after the pipe

Regex Flags Explained

Flags (also called modifiers) change how the engine processes the pattern. In JavaScript you append them after the closing slash: /pattern/gi. In Python you pass them as a second argument: re.findall(pattern, text, re.IGNORECASE | re.MULTILINE). Not all flags are available in every language.

FlagNameBehavior
gGlobalFind all matches, not just the first one
iCase-insensitiveLetters match both uppercase and lowercase
mMultiline^ and $ match start/end of each line, not just the whole string
sDot-all. matches newline characters as well
uUnicodeTreat the pattern and subject as a Unicode string; enables \u{FFFF} syntax
yStickyMatches only from the lastIndex position in the target string

Code Examples

Working regex examples in JavaScript, Python, Go, and the command line. Each example shows pattern construction, match extraction, and output.

JavaScript
// Match all email addresses in a string
const text = 'Contact us at support@example.com or sales@example.com'
const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g

const matches = text.matchAll(emailRegex)
for (const match of matches) {
  console.log(match[0], 'at index', match.index)
}
// β†’ "support@example.com" at index 14
// β†’ "sales@example.com" at index 37

// Named capture groups (ES2018+)
const dateRegex = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/
const result = '2026-03-30'.match(dateRegex)
console.log(result.groups)
// β†’ { year: "2026", month: "03", day: "30" }

// Replace with a callback
'hello world'.replace(/\b\w/g, c => c.toUpperCase())
// β†’ "Hello World"
Python
import re

# Find all IPv4 addresses
text = 'Server 192.168.1.1 responded, fallback to 10.0.0.255'
pattern = r'\b(?:\d{1,3}\.){3}\d{1,3}\b'

matches = re.findall(pattern, text)
print(matches)  # β†’ ['192.168.1.1', '10.0.0.255']

# Named groups and match objects
date_pattern = r'(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})'
m = re.search(date_pattern, 'Released on 2026-03-30')
if m:
    print(m.group('year'))   # β†’ '2026'
    print(m.group('month'))  # β†’ '03'

# Compile for repeated use (faster in loops)
compiled = re.compile(r'\b[A-Z][a-z]+\b')
words = compiled.findall('Hello World Foo bar')
print(words)  # β†’ ['Hello', 'World', 'Foo']
Go
package main

import (
	"fmt"
	"regexp"
)

func main() {
	// Find all matches
	re := regexp.MustCompile(`\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}\b`)
	text := "Contact support@example.com or sales@example.com"
	matches := re.FindAllString(text, -1)
	fmt.Println(matches)
	// β†’ [support@example.com sales@example.com]

	// Named capture groups
	dateRe := regexp.MustCompile(`(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})`)
	match := dateRe.FindStringSubmatch("2026-03-30")
	for i, name := range dateRe.SubexpNames() {
		if name != "" {
			fmt.Printf("%s: %s\n", name, match[i])
		}
	}
	// β†’ year: 2026
	// β†’ month: 03
	// β†’ day: 30

	// Replace with a function
	result := re.ReplaceAllStringFunc(text, func(s string) string {
		return "[REDACTED]"
	})
	fmt.Println(result)
	// β†’ Contact [REDACTED] or [REDACTED]
}
CLI (grep / sed)
# Find lines matching an IP address pattern
grep -E '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' access.log

# Extract email addresses from a file
grep -oE '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' contacts.txt

# Replace dates from YYYY-MM-DD to DD/MM/YYYY using sed
echo "2026-03-30" | sed -E 's/([0-9]{4})-([0-9]{2})-([0-9]{2})/\3\/\2\/\1/'
# β†’ 30/03/2026

# Count matches per file in a directory
grep -rcE 'TODO|FIXME|HACK' src/
# β†’ src/main.js:3
# β†’ src/utils.js:1

Frequently Asked Questions

What is the difference between regex and glob patterns?
Glob patterns (like *.txt or src/**/*.js) are a simplified wildcard syntax used for file path matching in shells and build tools. They support * (any characters), ? (one character), and [] (character classes) but lack quantifiers, groups, lookaheads, and alternation. Regex is far more expressive and operates on arbitrary text, not just file paths. A glob pattern *.json is roughly equivalent to the regex ^.*\.json$.
How do I match a literal dot or bracket in regex?
Prefix the character with a backslash: \. matches a literal period, \[ matches a literal bracket. Inside a character class [], a dot is already literal and does not need escaping. A common mistake is writing 192.168.1.1 without escaping the dots, which matches 192x168y1z1 because . means "any character."
Is my test data sent to a server?
No. This tool executes regex matching entirely in your browser using the JavaScript RegExp engine. No network requests are made with your text or pattern. You can confirm this by opening your browser DevTools Network tab while using the tool.
Why does my regex work in JavaScript but fail in Python?
JavaScript and Python use different regex engines with slightly different feature sets. JavaScript supports \d, lookaheads (?=), and lookbehinds (?<=) since ES2018, but does not support conditional patterns, atomic groups, or possessive quantifiers. Python's re module does not support \p{} Unicode property classes (use the third-party regex module instead). Always test in the target language's engine or consult the language's regex documentation.
What causes catastrophic backtracking in regex?
Catastrophic backtracking happens when a pattern has nested quantifiers that create an exponential number of matching paths. The classic example is (a+)+ applied to a string of a's followed by a non-matching character. The engine tries every possible way to split the a's between the inner and outer groups before failing. Fix this by using atomic groups (?>), possessive quantifiers a++, or rewriting the pattern to avoid ambiguous repetition.
Can I use regex to parse HTML?
Regex can extract simple values from HTML fragments, like pulling the href from a single <a> tag. For full HTML parsing, use a proper parser (DOMParser in JavaScript, BeautifulSoup in Python, or html/template in Go). HTML is a context-free grammar, and regex handles regular grammars. Nested tags, optional attributes, and self-closing elements create patterns that regex cannot match reliably.
What is the difference between greedy and lazy quantifiers?
A greedy quantifier (* or +) matches as many characters as possible, then backtracks if the rest of the pattern fails. A lazy quantifier (*? or +?) matches as few characters as possible, expanding only when needed. For the input <b>one</b><b>two</b>, the greedy pattern <b>.*</b> matches the entire string from the first <b> to the last </b>, while the lazy pattern <b>.*?</b> matches <b>one</b> and <b>two</b> separately.