What Is a Regular Expression?
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Originally developed in the 1950s by mathematician Stephen Kleene, regular expressions are used in virtually every programming language for pattern matching within strings — finding, replacing, validating, and extracting text that matches specific patterns.
Regular expressions are indispensable tools for developers, data analysts, system administrators, and anyone who works with text processing. They can match simple literal text or complex patterns including character classes, quantifiers, grouping, lookahead/lookbehind assertions, and backreferences.
How to Use This Tool
Enter your regex pattern in the pattern field between the forward slashes. Toggle the flags using the checkboxes or type them directly in the flags field. Type or paste your test string in the text area. Matches are highlighted in real time as you type, and match details including capture groups are displayed below.
Regex Flags Explained
- g (global): Find all matches in the string, not just the first one.
- i (case-insensitive): Ignore case differences when matching. "hello" matches "Hello", "HELLO", etc.
- m (multiline): Makes
^and$match the start/end of each line, not just the entire string. - s (dotAll): Makes the dot
.match newline characters (\n), which it normally does not. - u (unicode): Enables full Unicode matching, treating surrogate pairs as single characters and enabling Unicode property escapes.
Common Regex Patterns
- Email:
\b[\w.-]+@[\w.-]+\.\w{2,}\b - URL:
https?://[^\s/$.?#].[^\s]* - Phone (US):
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} - IP Address:
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b - Date (YYYY-MM-DD):
\d{4}-\d{2}-\d{2} - HTML Tag:
<[^>]+> - Hex Color:
#([0-9a-fA-F]{3}){1,2}\b
Regex Syntax Quick Reference
.— Any character (except newline without s flag)\d— Digit (0-9),\D— Non-digit\w— Word character (letter, digit, underscore),\W— Non-word\s— Whitespace,\S— Non-whitespace^— Start of string/line,$— End of string/line[abc]— Character class,[^abc]— Negated class*— 0 or more,+— 1 or more,?— 0 or 1{n}— Exactly n,{n,m}— Between n and m(abc)— Capture group,(?:abc)— Non-capture groupa|b— Alternation (a or b)(?=abc)— Positive lookahead,(?!abc)— Negative lookahead
Frequently Asked Questions
What is a regular expression?
A regular expression is a pattern that describes a set of strings. It is used for searching, matching, and manipulating text in programming. Virtually every language supports regex — JavaScript, Python, Java, PHP, Go, Ruby, and more.
What do the regex flags mean?
Flags modify how the regex engine processes the pattern. The most common are: g (global — find all matches), i (case-insensitive), m (multiline — ^ and $ match per line), s (dotAll — . matches newlines), and u (Unicode support).
Related Tools
- Text Case Converter — Convert text between different cases.
- JSON Formatter — Format and validate JSON data.