编写正则表达式,输入测试文本,实时查看匹配结果与捕获组
| # | Range | Match | Groups |
|---|---|---|---|
| No matches yet | |||
Regular Expressions (regex) are powerful text pattern matching tools widely used in programming. LitekitHub's Regex Tester provides real-time match highlighting, capture group display, token-by-token explanation, and multi-language code examples.
Anchors: ^ start, $ end, \b word boundary.
Character Classes: \d digit, \w word, \s whitespace, . any char, [abc] set, [^abc] negated.
Quantifiers: * 0+, + 1+, ? 0-1, {n} exactly n, {n,m} n to m. Append ? for lazy.
Groups: (...) capture, (?:...) non-capture, (?P<name>...) named, \1 backref, | OR.
Assertions: (?=...) positive lookahead, (?!...) negative lookahead, (?<=...) positive lookbehind, (?<!...) negative lookbehind.
Flags: g global, i case-insensitive, m multiline, s dotall, u unicode.
| Use Case | Pattern | Description |
|---|---|---|
[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,} | Standard email | |
| Phone | 1[3-9]\d{9} | China mobile |
| URL | https?://[^\s]+ | HTTP/HTTPS |
| IPv4 | (\d{1,3}\.){3}\d{1,3} | IPv4 addresses |
| Date | \d{4}-\d{2}-\d{2} | YYYY-MM-DD |
| Hex Color | #[0-9A-Fa-f]{6} | 6-digit color |
| Chinese | [\u4e00-\u9fa5]+ | Chinese chars |
| HTML Tag | <[^>]+> | HTML/XML tags |
| Password | (?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,} | 8+ chars with mix |
\d, \w, +, *.? for lazy mode.Try regex testing now!