Regex Tester: Regular Expression Cheat Sheet & Online Debugger

Tools 閲覧

What Is a Regular Expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. They're used for validating input, finding and replacing text, extracting data from strings, and parsing logs. Nearly every programming language has built-in regex support.

How to Test Regex Online

Use the tool.tl Regex Tester:

  1. Go to tool.tl/regex-tester
  2. Enter your pattern in the Regex field (e.g., \d+)
  3. Enter test text in the input area
  4. Matches highlight in real time
  5. See capture groups and match details below

Regex Syntax Quick Reference

Character Classes

PatternMeaningExample
.Any character except newlinea.c → abc, a1c
\dDigit [0-9]\d+ → 123
\wWord char [a-zA-Z0-9_]\w+ → hello_world
\sWhitespace (space, tab, newline)\s+ → spaces
\D \W \SNegations of aboveNon-digit, non-word, non-space
[abc]Character set: a or b or c[aeiou] → vowels
[^abc]Negated character set[^0-9] → non-digit

Quantifiers

QuantifierMeaning
*0 or more
+1 or more
?0 or 1 (optional)
{n}Exactly n times
{n,m}Between n and m times
{n,}n or more times

Anchors & Boundaries

AnchorMeaning
^Start of string (or line with multiline flag)
$End of string (or line)
\bWord boundary
\BNon-word boundary

Ready-to-Use Regex Patterns

# Email address
^[\w.+-]+@[\w-]+\.[\w.]{2,}$

# US phone number
^(\+1)?[\s.-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$

# IPv4 address
^(\d{1,3}\.){3}\d{1,3}$

# URL (http/https)
https?://[\w\-.]+(:\d+)?(/[\w\-./?%&=#]*)?$

# Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$

# Hex color code
^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

# Positive integer
^[1-9]\d*$

# Strong password (min 8 chars, upper+lower+digit+special)
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

# US ZIP code
^\d{5}(-\d{4})?$

# Credit card number (basic)
^\d{13,19}$

Capture Groups

Parentheses () create capture groups to extract specific parts of a match:

# Extract year, month, day from a date
Pattern: (\d{4})-(\d{2})-(\d{2})
Text:    2024-03-15
Group 1: 2024
Group 2: 03
Group 3: 15

// JavaScript
const m = '2024-03-15'.match(/(\d{4})-(\d{2})-(\d{2})/);
console.log(m[1]); // 2024
console.log(m[2]); // 03

# Python
import re
m = re.match(r'(\d{4})-(\d{2})-(\d{2})', '2024-03-15')
print(m.group(1))  # 2024

Frequently Asked Questions

Are regex patterns case-sensitive?

Yes, by default. Use the i flag to make matching case-insensitive: /hello/i matches Hello, HELLO, and hello. In the regex tester, you can toggle flags including i, g (global), and m (multiline).

How do I match a literal dot or asterisk?

Escape special characters with a backslash: \. matches a literal dot, \* matches a literal asterisk. Special characters that need escaping: . * + ? [ ] { } ( ) ^ $ | \

What's the difference between greedy and lazy matching?

Quantifiers are greedy by default (match as much as possible). Add ? after a quantifier to make it lazy (match as little as possible). On text <a><b>: <.*> matches the whole string, while <.*?> matches only <a>.