🔍 Regex Tester Online

Test regular expressions in real-time

/ /

Matches (0)

Quick Reference

. Any character
\d Digit [0-9]
\w Word char
\s Whitespace
^ Start of line
$ End of line
* 0 or more
+ 1 or more
? 0 or 1
{n} Exactly n
[abc] Character set
(abc) Group
💰Free Forever
🔓No Registration
🔒Privacy First
📴Works Offline

Frequently Asked Questions

What is a regular expression (regex)?

A regular expression is a sequence of characters that defines a search pattern. It's used for pattern matching within strings, validation, and text manipulation.

What regex flags are supported?

g (global), i (case-insensitive), m (multiline), s (dotAll), u (unicode). Enter them in the flags field after the regex.

How do I match digits only?

Use \d for a single digit or \d+ for one or more digits. [0-9] also matches digits.

How do I match email addresses?

A simple pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

What does the g flag do?

The global (g) flag finds all matches instead of stopping at the first one.

Is this tool secure?

Yes! All regex testing happens in your browser. Your data never leaves your device.

How do I escape special characters?

Use backslash: \. \* \+ \? \[ \] \( \) \{ \} \^ \$ \|

What is a capturing group?

Parentheses () create groups that capture matched text. Access them via match[1], match[2], etc.

How do I match the start/end of a line?

^ matches the start, $ matches the end. With 'm' flag, they match line boundaries.

Can I use this offline?

Yes! Once loaded, the tool works completely offline in your browser.

What is a regex tester?

A regex tester is an online tool that lets you write regular expressions and immediately see the results against test strings. It highlights matches, shows capture groups, and helps you debug patterns before using them in your code.

What does regex test return?

In most languages, regex test returns a boolean (true/false) indicating whether the pattern matches. In JavaScript: /pattern/.test(string) returns true or false. For actual matches, use match() or exec() instead.

How do I use a regex tester?

1) Enter your regular expression pattern in the regex field. 2) Add flags if needed (g for global, i for case-insensitive). 3) Type or paste your test string. 4) See matches highlighted instantly. Adjust your pattern until it matches exactly what you need.

Why does my regex work in tester but not in code?

Common reasons: 1) Different regex engines (Python vs JavaScript vs PCRE). 2) Missing or wrong flags. 3) Escape characters need double-escaping in strings (\d becomes \\d). 4) Different newline handling. Always test with your target language's engine.

Can I test regex patterns for different languages?

This tester uses JavaScript's regex engine. Most patterns work across languages, but there are differences. Python, Java, .NET, and PHP have their own quirks. See our code examples below for language-specific syntax.

What does regex pattern matching mean?

Pattern matching is finding text that matches a specific structure. For example, \d{3}-\d{4} matches phone numbers like "555-1234". The pattern defines the structure, and the regex engine finds all text matching that structure.

Regex Code Examples

Use your tested regex patterns in different programming languages.

JavaScript / Node.js

// Test if pattern matches (returns boolean)
const pattern = /\d+/g;
const text = "abc123def456";

// Test method - returns true/false
console.log(pattern.test(text)); // true

// Match method - returns array of matches
const matches = text.match(/\d+/g);
console.log(matches); // ["123", "456"]

// Exec method - returns match details with groups
const regex = /(\d+)/g;
let match;
while ((match = regex.exec(text)) !== null) {
    console.log(`Found ${match[0]} at index ${match.index}`);
}

Python

import re

text = "abc123def456"
pattern = r"\d+"

# Find all matches
matches = re.findall(pattern, text)
print(matches)  # ['123', '456']

# Search for first match
match = re.search(pattern, text)
if match:
    print(f"Found: {match.group()} at {match.start()}")

# Test if pattern matches (returns Match object or None)
if re.match(r"abc", text):
    print("Starts with 'abc'")

# Replace matches
result = re.sub(r"\d+", "NUM", text)
print(result)  # "abcNUMdefNUM"

Java

import java.util.regex.*;

String text = "abc123def456";
String patternStr = "\\d+";

// Compile pattern
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(text);

// Find all matches
while (matcher.find()) {
    System.out.println("Found: " + matcher.group() + 
                       " at " + matcher.start());
}

// Test if entire string matches
boolean fullMatch = text.matches(".*\\d+.*");

// Replace matches
String result = text.replaceAll("\\d+", "NUM");
System.out.println(result); // "abcNUMdefNUM"

PHP

$text = "abc123def456";
$pattern = "/\d+/";

// Find all matches
preg_match_all($pattern, $text, $matches);
print_r($matches[0]); // Array("123", "456")

// Find first match
if (preg_match($pattern, $text, $match)) {
    echo "Found: " . $match[0];
}

// Replace matches
$result = preg_replace($pattern, "NUM", $text);
echo $result; // "abcNUMdefNUM"

// Test with named groups
preg_match('/(?P\d+)/', $text, $match);
echo $match['num']; // "123"

Bash / Shell

# Using grep
echo "abc123def456" | grep -oE '[0-9]+'
# Output: 123
#         456

# Using sed for replacement
echo "abc123def456" | sed 's/[0-9]\+/NUM/g'
# Output: abcNUMdefNUM

# Bash regex matching (=~ operator)
text="abc123def456"
if [[ $text =~ [0-9]+ ]]; then
    echo "Match: ${BASH_REMATCH[0]}"  # 123
fi

# Using awk
echo "abc123def456" | awk '{gsub(/[0-9]+/, "NUM"); print}'

.NET (C#)

using System.Text.RegularExpressions;

string text = "abc123def456";
string pattern = @"\d+";

// Find all matches
MatchCollection matches = Regex.Matches(text, pattern);
foreach (Match match in matches) {
    Console.WriteLine($"Found: {match.Value} at {match.Index}");
}

// Test if matches
bool isMatch = Regex.IsMatch(text, pattern);

// Replace
string result = Regex.Replace(text, pattern, "NUM");

// Compiled regex for better performance
Regex compiledRegex = new Regex(pattern, RegexOptions.Compiled);