What is a Regular Expression?
A regular expression (regex or regexp) is a sequence of characters that forms a search pattern. You can use this pattern to match, find, replace, or validate strings in text. Regular expressions are supported in virtually every programming language — JavaScript, Python, Java, Go, PHP, Ruby, and many others — as well as in text editors, database engines, and command-line tools like grep and sed.
At their core, regular expressions describe what text should look like. A regex like \d{3}-\d{4} matches exactly three digits, a hyphen, and four more digits — a format common in phone numbers. A regex like [a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} matches email addresses.
How to Use the Regex Tester
- Enter your regular expression in the Regular Expression field.
- Paste or type the text you want to test in the Test String area.
- Matches are highlighted in real time. The panel on the right shows all matches with their index positions and any capture groups.
- Use the flag checkboxes to toggle global (
g), case-insensitive (i), multiline (m), and dotAll (s) modes. - Click any snippet button to load a ready-made pattern for common use cases.
Regex Flags Explained
| Flag | Letter | Effect |
|---|---|---|
| Global | g | Find all matches, not just the first one |
| Ignore case | i | Match letters regardless of case (A = a) |
| Multiline | m | ^ and $ match start/end of each line, not just the whole string |
| DotAll | s | The dot . matches newline characters as well |
You can combine flags freely. For example, gi matches all occurrences case-insensitively.
Regex Syntax Quick Reference
| Pattern | Matches |
|---|---|
. | Any character except newline (with s flag: including newline) |
\d | Any digit (0–9) |
\w | Any word character (letter, digit, underscore) |
\s | Any whitespace (space, tab, newline) |
\b | Word boundary |
^ | Start of string (or line with m flag) |
$ | End of string (or line with m flag) |
[abc] | Any character in the set: a, b, or c |
[^abc] | Any character NOT in the set |
a|b | Either a or b (alternation) |
(...) | Capture group |
(?<name>...) | Named capture group |
(?:...) | Non-capturing group |
a{3} | Exactly 3 repetitions of a |
a{2,4} | Between 2 and 4 repetitions |
a+ | One or more repetitions (greedy) |
a* | Zero or more repetitions |
a? | Zero or one repetition |
Capture Groups
Capture groups let you extract specific parts of a match. Enclose any part of your pattern in parentheses to create a capture group. For example, in the pattern (\d{4})-(\d{2})-(\d{2}) applied to 2024-06-07, group 1 captures 2024, group 2 captures 06, and group 3 captures 07.
Named groups ((?<year>\d{4})) make the captured value accessible by name rather than index, which is useful when the pattern has many groups.
Common Regex Patterns
The snippet bar above the pattern field provides ready-made patterns for:
- Email addresses — matches standard RFC-compliant email formats
- URLs — matches
http://andhttps://links - IP addresses — matches IPv4 addresses in dotted-decimal notation
- ISO dates — matches dates in
YYYY-MM-DDformat - German phone numbers — matches numbers starting with
+49or0 - HEX colors — matches
#RGBand#RRGGBBcolor codes
Privacy
All regex matching runs entirely in your browser using the built-in JavaScript RegExp engine. Your patterns and test strings never leave your device and are not stored anywhere.