/ /

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

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.

Frequently Asked Questions

What is a regular expression?
A regular expression is a sequence of characters that defines a search pattern. Regex engines scan text to find substrings matching the pattern. They are used in programming, text editors, command-line tools, and databases for search, validation, and text transformation.
What is the difference between .* and .+?
.* matches zero or more of any character, meaning it can match an empty string. .+ matches one or more, requiring at least one character to be present. Use .+ when something must exist; use .* when it is optional.
How do I match a specific number of characters?
Use curly brace quantifiers: {n} matches exactly n, {n,} matches n or more, {n,m} matches between n and m. Example: \d{4} matches exactly 4 digits, [A-Z]{2,5} matches 2 to 5 uppercase letters.
How do I validate an email address with regex?
A basic pattern: ^[\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.
How do I use regex in Python and JavaScript?
Python: 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.
Related tools
Ad