Basic Regex Cheat Sheet
【摘要】 Symbols“^” : Matches the beginning of the string.“$” : Matches the end of the string.“ . ” : Matches any single character, except for line breaks.“ * “ : Matches the preceding expression zero or mo...
Symbols
- “^” : Matches the beginning of the string.
- “$” : Matches the end of the string.
- “ . ” : Matches any single character, except for line breaks.
- “ * “ : Matches the preceding expression zero or more times.
Characters
- “ \d “ : Any single digit character. Ex: 1, 2, 3, …
- “ \w “ : Any word character (alphanumeric & underscore). Ex: a, A, b, B, …
- “ \W “ : Any character that is not a word character. Ex: *,-,+,=
- “ \D “ : Any character that is not a digit . Ex: a,B,+
- “ \s “ : Whitespace
Classes
- “ [abc] ” : Character Set: Any single character from the character within the brackets. Values: a, b, c
- “ [a-z] “ : Character Set: Character range, start from “a” to “z”, all lowercase letters.Ex: a,b,c, …
- “ [a-z]+” : One or more of any of the characters in the set.
- “ [^a-z] ”: Inside a character set, the ^ is used for negation. In this example, match anything that is NOT a lowercase letter.
Logic
- “ | “ : OR operand. Ex: 22|33
- “ ( … ) ” : Capturing group. Ex : B(arman|eer)
- “ (?: … ) ” : Non-capturing group. Ex: B(?:arman|eer)
Quantifiers
- “ +“ : Matches the preceding expression 1 or more times.
- “ {3} “ : Exactly three times. Ex: d{3} -> 123, 321
- “ ? ” : Preceding expression is optional (Matches 0 or 1 times).
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)