What Is a Regular Expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. It's used to find, match, validate, and replace text in strings. Regex is supported in virtually every programming language — JavaScript, Python, Java, Go, PHP, Ruby — making it one of the most universally useful developer skills. This tester uses the JavaScript RegExp engine (ECMAScript) and runs entirely in your browser; nothing is sent to any server.
Regex Quick Reference
Character classes
.— any character except newline\d— digit [0-9]\D— non-digit\w— word character [a-zA-Z0-9_]\W— non-word character\s— whitespace\S— non-whitespace
Quantifiers
*— 0 or more+— 1 or more?— 0 or 1{n}— exactly n{n,}— n or more{n,m}— between n and m
Anchors & groups
^— start of string/line$— end of string/line\b— word boundary(abc)— capture group(?:abc)— non-capturing(?<name>abc)— named group(?=abc)— positive lookahead(?!abc)— negative lookahead
JavaScript flags
g— global (find all matches)i— case insensitivem— multiline (^ $ per line)s— dotAll (. matches newline)u— unicodey— sticky
Common Regex Patterns
Try these in the tester above — use the Sample patterns dropdown to load them.
- Email:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ - URL:
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256} - Phone (US):
^\+?1?\s?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$ - Date (YYYY-MM-DD):
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ - IPv4:
^(\d{1,3}\.){3}\d{1,3}$ - Password (min 8 chars, upper, lower, number):
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$
Frequently Asked Questions
- How do I test a regex pattern online?
- Paste your regular expression in the pattern field and your test string below it. Matches highlight instantly in real time. The results table shows every match, its position index, and any capture groups. No clicking required — results update as you type.
- What is the g flag in JavaScript regex?
- The g (global) flag makes the regex find ALL matches in the string instead of stopping after the first one. Without g, only the first match is returned. Most use cases require the g flag when searching or replacing in strings.
- How do I use capture groups in regex replace?
- Wrap the part you want to capture in parentheses in your pattern. In the replacement field, reference it with $1 (first group), $2 (second group), and so on. For example: pattern
(\w+)\s(\w+)with replacement$2 $1swaps the first two words. - What is the difference between + and * in regex?
- * matches 0 or more occurrences — it can match nothing. + matches 1 or more — it requires at least one match. Use + when the character must appear at least once. Use * when it's optional.
- What does \d mean in regex?
- \d matches any digit character — equivalent to the character class [0-9]. Use \d+ to match one or more digits, \d4 to match exactly 4 digits. Use \D (uppercase) for the opposite — any non-digit character.
Related Tools
Pair regex with these developer tools: