Regular Expression (regex or regexp) is a pattern used to match character combinations in strings. It consists of a sequence of characters and special characters that describe a search pattern.
Regular expressions are widely used in:
A simple example: regex \d+ matches one or more digits, like "123" or "4567".
Basic components of regular expressions:
a matches "a"., *, +[a-z]{2,4} for 2 to 4 times(abc)+| Metachar | Description | Example |
|---|---|---|
| . | Matches any single character except newline | a.c matches "abc", "a1c" |
| ^ | Matches start of string | ^Hello matches strings starting with "Hello" |
| $ | Matches end of string | world$ matches strings ending with "world" |
| * | Matches preceding element zero or more times | ab*c matches "ac", "abc", "abbc" |
| + | Matches preceding element one or more times | ab+c matches "abc", "abbc", not "ac" |
| ? | Matches preceding element zero or one time | colou?r matches "color" or "colour" |
| \d | Matches any digit, same as [0-9] | \d+ matches "123" |
| \D | Matches any non-digit character | \D+ matches "abc" |
| \w | Matches word characters (letters, digits, underscore) | \w+ matches "hello_123" |
| \W | Matches non-word characters | \W matches "@", "#" |
| \s | Matches any whitespace character | \s+ matches spaces, tabs |
| \S | Matches any non-whitespace character | \S+ matches "hello" |
| \b | Matches word boundary | \bword\b matches exact "word" |
| [...] | Character class, matches any char in brackets | [aeiou] matches any vowel |
| [^...] | Negated class, matches chars not in brackets | [^0-9] matches non-digit |
| (...) | Capturing group | (\d+)-(\d+) captures two digit groups |
| (?:...) | Non-capturing group | (?:ab)+ matches but doesn't capture |
| | | Alternation, matches left or right expression | cat|dog matches "cat" or "dog" |
| {n} | Matches exactly n times | \d{4} matches 4 digits |
| {n,} | Matches at least n times | \d{2,} matches 2+ digits |
| {n,m} | Matches between n and m times | \d{2,4} matches 2 to 4 digits |
| Flag | Name | Description |
|---|---|---|
| g | global | Global match, find all matches instead of stopping after first |
| i | ignoreCase | Case-insensitive matching |
| m | multiline | Multiline mode, ^ and $ match start/end of each line |
| s | dotAll | Single line mode, makes . match newline characters |
| u | unicode | Enable Unicode matching mode |
| y | sticky | Sticky matching, only match from lastIndex position |
A regular expression is a pattern matching syntax used to search, validate, and replace text. It consists of ordinary characters and special characters (metacharacters) that can describe complex text patterns, widely used in data validation, text search, and string processing.
g (global) enables global matching, finding all matches instead of stopping after the first; i (ignoreCase) enables case-insensitive matching; m (multiline) enables multiline mode where ^ and $ match the start and end of each line.
Use [\u4e00-\u9fa5] to match common Chinese characters. This range covers all Chinese characters in the CJK Unified Ideographs basic block.
Common reasons include: 1. Special characters not escaped (. * + need backslash); 2. Greedy matching captures too much (use ? for non-greedy); 3. Incorrect flags (missing global flag returns only first result); 4. Boundary conditions not considered (^ $ usage).
This tool uses JavaScript regular expression syntax (ECMAScript specification). It supports common metacharacters, character classes, quantifiers, groups, assertions, and flags like g, i, m, s, u.
Yes, 100% free with no ads, no registration, no watermark, and no usage limits. All processing happens locally in your browser — your data is never uploaded to any server.