Regex Tester
Write a pattern, test it against your text — matches highlighted live with capture group details.
About the Regex Tester
Regular expressions (regex) are patterns used to search, match, and manipulate text. They are supported in virtually every programming language and are built into text editors, command-line tools, and database engines. A single regex can replace dozens of lines of string-manipulation code, making them essential for data validation, text extraction, and format transformation.
Essential regex syntax
- . — any character except newline
- * + ? — zero-or-more, one-or-more, optional
- ^ $ — start and end of string
- [abc] — any character in the set; [^abc] — any character NOT in the set
- \d \w \s — digit, word character, whitespace
- {n,m} — between n and m repetitions
- (group) — capture group; (?:group) — non-capturing group
Common regex flags
Flags modify matching behaviour. i makes matching case-insensitive. g finds all matches, not just the first. m makes ^ and $ match line starts and ends rather than string boundaries. s makes . match newlines.
Lookahead and lookbehind assertions
Lookahead and lookbehind (collectively lookbehind) are zero-width assertions: they check what comes before or after a position without consuming characters in the match. (?=pattern) is positive lookahead (match only if followed by pattern). (?!pattern) is negative lookahead. (?<=pattern) is positive lookbehind. These are powerful for matching text based on context without including that context in the captured result.
- Positive lookahead (?=...) — match "foo" only if followed by "bar":
foo(?=bar) - Negative lookahead (?!...) — match "foo" not followed by "bar":
foo(?!bar) - Positive lookbehind (?<=...) — match "bar" only if preceded by "foo":
(?<=foo)bar - Negative lookbehind (?<!...) — match "bar" not preceded by "foo":
(?<!foo)bar
Frequently Asked Questions
^[\w.+-]+@[\w-]+\.[\w.]+$. This catches obvious errors but full RFC 5322 compliance requires a much longer expression. In practice, send a confirmation email — it remains the only reliable validation method.import re; re.findall(r"\d+", text). JavaScript: text.match(/\d+/g). Grep on command line: grep -E "\d+" file.txt. The syntax is mostly consistent across languages, though some advanced features vary.