Regex Generator
A regex (regular expression) generator creates patterns for matching text. Common patterns: email = ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$, URL = https?://..., phone = \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}. Use \d for digits, \w for word characters, + for one-or-more, * for zero-or-more, ? for optional. Flags: g (global), i (case-insensitive), m (multiline).
Generate regular expressions visually or pick from a library of common patterns. Includes email, URL, phone, IP address, date, and password validation patterns. Visual builder lets you construct regex step by step. Test against sample text with match highlighting. Code snippets for JavaScript, Python, and Java.
Mode
Common Patterns
Flags
Generated Regex
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/gCode Snippets
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/g;
const matches = text.match(regex);import re
pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
matches = re.findall(pattern, text)Pattern pattern = Pattern.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$");
Matcher matcher = pattern.matcher(text);Test String
Regex Quick Reference
| Pattern | Meaning | Example |
|---|---|---|
| . | Any character | a.c matches "abc", "a1c" |
| \d | Any digit (0-9) | \d{3} matches "123" |
| \w | Word character (a-z, A-Z, 0-9, _) | \w+ matches "hello_1" |
| \s | Whitespace (space, tab, newline) | a\sb matches "a b" |
| ^ | Start of string | ^Hello matches "Hello world" |
| $ | End of string | world$ matches "hello world" |
| * | Zero or more | ab*c matches "ac", "abc", "abbc" |
| + | One or more | ab+c matches "abc", "abbc" |
| ? | Zero or one | colou?r matches "color", "colour" |
| {n} | Exactly n times | \d{4} matches "2026" |
| {n,m} | Between n and m times | \d{2,4} matches "12", "123", "1234" |
| [abc] | Any of a, b, or c | [aeiou] matches vowels |
| [^abc] | Not a, b, or c | [^0-9] matches non-digits |
| (abc) | Capture group | (\d+)-(\d+) captures both parts |
| a|b | a or b | cat|dog matches "cat" or "dog" |
How to Use
- 1
Choose a mode
Use Pattern Library for common patterns (email, URL, phone, IP) or Visual Builder to construct regex step by step with character classes, quantifiers, and groups.
- 2
Select or build pattern
In library mode, click a pattern to use it. In builder mode, add parts with character types (literal, digit, word, any), quantifiers (+, *, ?, {n,m}), and optional grouping.
- 3
Test the pattern
Paste sample text in the test area. Matches are highlighted with their index positions. Enable global (g), case-insensitive (i), or multiline (m) flags as needed.
- 4
Copy the regex
Copy the generated pattern or use the ready-made code snippets for JavaScript, Python, or Java directly in your project.
Frequently Asked Questions
- What is a regular expression (regex)?
- A regular expression (regex) is a pattern that describes a set of strings. It uses special characters like . (any character), \d (digit), * (zero or more), and + (one or more) to match text patterns. Regex is used in programming, search, and text processing to find, validate, or replace strings. For example, ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ matches email addresses.
- What is the regex for validating an email address?
- A common email regex is: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$. This matches a local part (letters, digits, dots, underscores, percent, plus, hyphen), followed by @, a domain name, a dot, and a TLD of 2+ characters. Note: RFC 5322 allows more complex formats, but this pattern covers 99% of real-world email addresses.
- How do regex quantifiers work?
- Quantifiers control how many times a pattern repeats. * means zero or more (ab*c matches "ac", "abc", "abbc"). + means one or more (ab+c matches "abc" but not "ac"). ? means zero or one (colou?r matches "color" and "colour"). {n} matches exactly n times. {n,m} matches between n and m times. {n,} matches n or more times.
- What is the difference between . and \. in regex?
- In regex, . (dot) is a special character that matches any single character except newline. \. (escaped dot) matches a literal period/dot character. For example, a.b matches "aXb", "a1b", "a.b" — any character between a and b. But a\.b only matches "a.b". Always escape dots when matching literal periods in URLs, IP addresses, or file extensions.
- What are capture groups in regex?
- Capture groups use parentheses () to extract parts of a match. In the pattern (\d{3})-(\d{4}), matching "555-1234" captures "555" as group 1 and "1234" as group 2. Non-capturing groups (?:...) group without capturing. Named groups (?P<name>...) or (?<name>...) assign names to captures. In JavaScript: "555-1234".match(/(\d{3})-(\d{4})/) returns ["555-1234", "555", "1234"].
- What regex flags are available?
- Common regex flags: g (global) finds all matches instead of stopping at the first. i (case-insensitive) matches regardless of case. m (multiline) makes ^ and $ match line starts/ends. s (dotAll) makes . match newlines too. u (unicode) enables full Unicode support. In JavaScript: /pattern/gi. In Python: re.compile(pattern, re.IGNORECASE | re.MULTILINE).