关于正则表达式工具
什么是正则表达式?
正则表达式(Regular Expression)是一种用于匹配和处理字符串的强大工具。它使用特定的语法定义搜索模式,可用于验证输入格式、提取特定内容、替换文本等操作。几乎所有主流编程语言都支持正则表达式。
Syntax Reference
| Syntax | Description | Example |
|---|---|---|
| \d | Digit | \d+ → "123" |
| \w | Word char | \w+ → "hello" |
| \s | Whitespace | \s → " " |
| . | Any char | a.b → "aab" |
| * | Zero or more | a* → "" / "aaa" |
| + | One or more | a+ → "a" / "aaa" |
| ? | Zero or one | a? → "" / "a" |
| {n,m} | n to m times | a{2,4} → "aa"~"aaaa" |
| [abc] | Char class | [aeiou] → vowel |
| [^abc] | Negated class | [^0-9] → non-digit |
| ^ | Start of line | ^Hello |
| $ | End of line | end$ |
| ( ) | Capture group | (\d+)-(\d+) |
| (?: ) | Non-capturing | (?:ab)+ |
| | | Alternation | cat|dog |