DevTools

Regex Tester Online — Test & Validate Regular Expressions

Test, debug and explore regular expressions with real-time matching and replacement.

Regex
Enter regex and text to see matches

What Is a Regular Expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. The pattern can be as simple as a literal string or as complex as a nested combination of quantifiers, character classes, anchors, and groups. Regex engines compare the pattern against input text and report which portions match.

Regular expressions are built into virtually every programming language and are available in most text editors and command-line tools. Developers rely on a regex tester to validate email addresses, phone numbers, and URL formats in form validation. System administrators use regular expression online tools to filter log lines and extract fields from structured output. Editors like VS Code and Vim treat regex as a first-class search primitive, letting you rename identifiers or reformat dates across thousands of files in seconds.

Four flags control how a match is performed. The global flag (g) finds every occurrence in the input rather than stopping at the first. The case-insensitive flag (i) makes regex match uppercase and lowercase letters interchangeably. The multiline flag (m) redefines the anchor characters ^ and $ so they match at line boundaries instead of only at the very start and end of the string. The dotAll flag (s) makes the dot . match newline characters as well, which matters when a pattern needs to span multiple lines. Understanding when to combine these flags separates brittle patterns from reliable ones.

How to Test a Regular Expression Online

  1. 1
    Enter your pattern. Type your regex in the pattern field. Set flags (g, i, m, s) as needed using the flag toggles beside the input.
  2. 2
    Provide test strings. Paste sample text into the test input. Matches are highlighted in real time as you adjust the pattern or flags.
  3. 3
    Review matches. The tool shows all matches, capture groups, and their character positions. Switch to replace mode to preview substitutions instantly.

Regex Flags and Syntax Guide

Open the regex tester and type your pattern into the pattern field. Select any flags you need — g to find all matches, i to ignore case, m to match across lines, s to let the dot match newlines. Paste representative sample text into the test input below. The tool highlights every match in real time as you type, so you can iterate on the pattern without running any code.

When your pattern includes capture groups, the results panel lists each group's matched value and its character position in the source text. Switch to replace mode to preview substitutions before applying them. Once you have extracted the fields you need, format them with the JSON Formatter or decode any captured tokens with the URL Encoder. Because all processing happens client-side, no data ever leaves your browser.

Code Examples

JavaScript / TypeScript
// Test a pattern with the RegExp constructor
const pattern = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi;
const input = "Contact us at [email protected] or [email protected]";

// Find all matches
const matches = input.match(pattern);
console.log(matches);
// ["[email protected]", "[email protected]"]

// Named capture groups
const dateRe = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const { groups } = "2026-04-13".match(dateRe);
console.log(groups); // { year: "2026", month: "04", day: "13" }

// Replace with back-references
const result = "2026-04-13".replace(dateRe, "$<day>/$<month>/$<year>");
console.log(result); // "13/04/2026"
Python
import re

# Compile a pattern for reuse
pattern = re.compile(r"\b\d{1,3}(?:\.\d{1,3}){3}\b")
text = "Server 192.168.1.1 forwarded to 10.0.0.254"

# Find all matches
matches = pattern.findall(text)
print(matches)  # ['192.168.1.1', '10.0.0.254']

# Named capture groups
date_re = re.compile(r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})")
m = date_re.search("Release date: 2026-04-13")
if m:
    print(m.group("year"), m.group("month"), m.group("day"))
    # 2026 04 13

# Substitution
result = date_re.sub(r"\g<day>/\g<month>/\g<year>", "2026-04-13")
print(result)  # 13/04/2026
Go
package main

import (
    "fmt"
    "regexp"
)

func main() {
    // Compile the pattern
    pattern := regexp.MustCompile(`\b[\w.+-]+@[\w-]+\.[a-z]{2,}\b`)
    input := "Send mail to [email protected] and [email protected]"

    // Find all matches
    matches := pattern.FindAllString(input, -1)
    fmt.Println(matches)
    // [[email protected] [email protected]]

    // Named capture groups
    dateRe := regexp.MustCompile(`(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})`)
    match := dateRe.FindStringSubmatch("2026-04-13")
    names := dateRe.SubexpNames()
    for i, name := range names {
        if name != "" && i < len(match) {
            fmt.Printf("%s: %s\n", name, match[i])
        }
    }
    // year: 2026  month: 04  day: 13
}
Bash
# grep -E uses extended regex; -o prints only matching text
echo "Contact: [email protected]" | grep -Eo '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}'
# [email protected]

# Case-insensitive match across a log file
grep -iE 'error|warn' /var/log/app.log

# Extract capture group with sed
echo "2026-04-13" | sed -E 's/([0-9]{4})-([0-9]{2})-([0-9]{2})/\3\/\2\/\1/'
# 13/04/2026

# Count lines matching a pattern
grep -cE '^[[:space:]]*$' file.txt  # count blank lines

Frequently Asked Questions

What is a regular expression (regex)?

A regular expression is a pattern of characters that defines a search rule for matching text. It is used in virtually every programming language and text editor.

How do I test a regex online?

Type your regex pattern in the pattern field, enter your test text below, and matches are highlighted in real time. You can toggle flags and use replace mode.

What do regex flags g, i, m, and s mean?

g (global) finds all matches. i (case-insensitive) ignores letter casing. m (multiline) makes ^ and $ match the start and end of each line. s (dotAll) lets the dot . match newline characters too, so a pattern can span multiple lines.

Can I use capture groups and back-references?

Yes. Use parentheses () to create capture groups. In the replace field, reference them with $1, $2, etc. Named groups (?<name>...) are also supported.

How do I check if my regular expression is valid?

Type your pattern into the field above. If the syntax is invalid, the tester shows a red error message explaining what went wrong (for example an unterminated group or character class); if it compiles, your matches highlight in real time. That instant feedback is the quickest way to validate a regular expression before pasting it into code.

Related Developer Tools