A regular expression (regex) is a sequence of characters that defines a search pattern, used for string matching, validation, and text extraction. Regex syntax — standardized in POSIX and extended by PCRE (Perl Compatible Regular Expressions) — includes quantifiers (+, *, ?), character classes ([a-z], \d, \w), anchors (^, $), and capture groups. Regular expressions are supported natively in JavaScript, Python, Java, Go, and virtually every modern programming language.
What is a Regular Expression?
A regular expression (regex) is a pattern that describes a set of strings. It's the standard tool for searching, validating, and transforming text in programming. Regex is supported in every major language — JavaScript, Python, Java, Go, Rust, PHP — and in tools like grep, sed, and most text editors.
A regex combines literal characters with special metacharacters. For example, \d3-\d4 matches a 3-digit number, a dash, and a 4-digit number (like a US phone suffix).
What are the most common regex syntax elements?
| Pattern | Meaning |
|---|---|
| . | Any character (except newline) |
| \d | Digit (0-9) |
| \w | Word character (a-z, A-Z, 0-9, _) |
| \s | Whitespace (space, tab, newline) |
| ^ | Start of string/line |
| $ | End of string/line |
| * | 0 or more |
| + | 1 or more |
| ? | 0 or 1 (optional) |
| {n,m} | Between n and m times |
| [abc] | Character class (a, b, or c) |
| (abc) | Capture group |
| a|b | Alternation (a or b) |
What are the most common regex patterns?
- Email:
^[\w.-]+@[\w.-]+\.\w{2,}$ - URL:
https?://[\w.-]+(?:/[\w./-]*)? - IPv4:
\b\d{1,3}(?:\.\d{1,3}){3}\b - Date (ISO):
\d{4}-\d{2}-\d{2}
If you work with scheduled tasks, our cron expression generator can help you build crontab schedules visually. For encoding data, check the Base64 encoder.