What is Regular Expression (Regex)?
A regular expression (regex) is a sequence of characters that defines a search pattern. It is used to match, validate, search, and replace text — for example validating an email or extracting all URLs from a document.
Regex is supported in virtually every programming language and editor. The syntax (anchors, character classes, quantifiers, groups) is largely shared across "flavors" like JavaScript, PCRE, and Python.
Key points
- Built from anchors, character classes, quantifiers, and groups.
- Flags like i (case-insensitive) and g (global) change matching behavior.
- Greedy quantifiers match as much as possible; add ? to make them lazy.
- Syntax is largely shared across JavaScript, PCRE, and Python.
Example
/^[\w.+-]+@[\w-]+\.[\w.-]+$/ matches a basic email address
Common uses
- Validating input like emails, phone numbers, and URLs
- Search-and-replace in editors and code
- Extracting structured data from logs or text
- URL routing and pattern matching
Work with Regular Expression (Regex) directly in your browser.
Open the Regex Tester