^
Start of line/string
Practical example
^Hello # matches "Hello world" but not "say Hello"
developer reference
A practical Regex reference with search, one-click copy and printable PDF output.
This tester uses JavaScript RegExp with global matching (g). Use (?<name>...) for named groups. Python re syntax and flags shown below run in Python, not in this tester. Limits: 100,000 text characters, 4,000 pattern characters, 1,000 matches; slow patterns are stopped.
35 commands visible
^
Start of line/string
^Hello # matches "Hello world" but not "say Hello"
$
End of line/string
world$ # matches "Hello world" but not "world class"
\b
Word boundary: word/non-word edge
\bcat\b # "cat" but not "catch" or "concat"
\B
Non-word boundary
\Bcat\B # "concatenate" but not " cat "
*
0 or more times (greedy)
ab*c # "ac", "abc", "abbc", "abbbc"…
+
1 or more times (greedy)
ab+c # "abc", "abbc" but NOT "ac"
?
0 or 1 time (optional)
colou?r # "color" and "colour"
{n,m}
Between n and m times
\d{2,4} # 2, 3 or 4 digits
\d{3} # exactly 3 digits
*? +? ??
Lazy versions (non-greedy)
# input: "<b>bold</b>"
<.+> # greedy: "<b>bold</b>"
<.+?> # lazy: "<b>" then "</b>"
[abc]
Character class: one of the listed characters
[aeiou] # any vowel
[a-z] # lowercase a-z
[A-Za-z0-9]
[^abc]
Negation: any character except listed ones
[^0-9] # non-digits
\d \w \s
Shorthand: \d digit, \w word, \s whitespace
\d # [0-9]
\w # [a-zA-Z0-9_]
\s # [ \t\n\r]
\D \W \S
Negated shorthands
\D # not a digit
\W # not a word character
\S # not whitespace
.
Any character except line terminators; the s flag (Python re.S) also matches newlines
a.b # "aXb", "a b", "a1b"…
(...)
Capturing group: captures the match
(\d{4})-(\d{2})-(\d{2})
# matches "2024-01-15", group(1)="2024"
(?:...)
Non-capturing group: groups without capturing
(?:Mr|Mrs|Ms)\.\s\w+
# groups alternatives without capturing
(?<name>...)
Named group: captures with a name
JavaScript: (?<year>\d{4})-(?<month>\d{2})
match.groups.year
Python: (?P<year>\d{4})-(?P<month>\d{2})
m.group("year")
a|b
Alternative: a or b
cat|dog # "cat" or "dog"
(https?|ftp)://
(?=...) (?!...)
Positive and negative lookahead
\d+(?= euro) # number followed by " euro" (does not capture " euro")
\d+(?! euro) # number NOT followed by " euro"
(?<=...) (?<!...)
Positive and negative lookbehind
(?<=\$)\d+ # number preceded by "$"
re.search (pattern, string)
Finds first occurrence anywhere
import re
m = re.search(r"\d+", "abc 123 def")
if m:
print(m.group()) # "123"
re.match (pattern, string)
Matches only at the beginning of the string
re.match(r"\d+", "123abc") # match
re.match(r"\d+", "abc123") # None
re.findall (pattern, string)
Returns a list of all matches
re.findall(r"\d+", "1 apple, 2 bananas, 3 pears")
# → ["1", "2", "3"]
re.sub (pattern, repl, string)
Replaces matches with repl
re.sub(r"\s+", " ", "too many spaces")
# → "too many spaces"
re.sub(r"(\w+)", r"[\1]", "hello world")
# → "[hello] [world]" (backreference)
re.split (pattern, string)
Splits a string on pattern matches
re.split(r"[,;\s]+", "a, b; c d")
# → ["a", "b", "c", "d"]
re.compile (pattern, flags)
Precompiles a pattern for repeated use
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+")
for line in lines:
if EMAIL.search(line): ...
re.IGNORECASE
Case-insensitive matching
re.findall(r"hello", text, re.I)
re.compile(r"hello", re.IGNORECASE)
re.MULTILINE
^ and $ match start/end of each line
re.findall(r"^\w+", text, re.M)
re.DOTALL
Dot (.) also matches newline
re.search(r"<div>.+?</div>", html, re.S)
re.VERBOSE
Allows comments in the pattern (re.X)
pattern = re.compile(r"""
\d{4} # year
-
\d{2} # month
""", re.X)
[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}
Simple email-shaped pattern; not a complete email validator
[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}
https?://[\w/:%#$&?()~.=+\-]+
Simple HTTP/HTTPS URL pattern; not a complete URL parser
https?://[\w/:%#$&?()~.=+\-]+
\b(?:\d{1,3}\.){3}\d{1,3}\b
IPv4-shaped pattern; does not validate octet ranges (0–255)
\b(?:\d{1,3}\.){3}\d{1,3}\b
\b\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])\b
YYYY-MM-DD-shaped pattern; does not validate calendar dates
\b\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])\b
(?:\+39)?[\s-]?(?:0\d{1,4}|3\d{2})[\s-]?\d{6,8}
Simplified Italian phone number pattern; does not confirm a valid or assigned number
(?:\+39)?[\s-]?(?:0\d{1,4}|3\d{2})[\s-]?\d{6,8}
The tester runs JavaScript RegExp. Python-specific syntax such as (?P<name>...) and re.VERBOSE must be tested in Python. The ready-made patterns illustrate formats, not complete validation.
Use Print PDF. The printable version includes all commands and practical examples, including sections hidden by a search.
Yes. Serve the static files with a local HTTP server. Search, filters and copying run in your browser; the Regex tester requires a worker-enabled HTTP context.