Basic Regex Cheat Sheet

举报
BitM 发表于 2021/10/27 18:03:31 2021/10/27
【摘要】 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 end of the string.
  • “ . ” : Matches any single character, except for line breaks.
  • “ * “ : Matches the preceding expression zero or more times.

Characters

  • “ \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

  •  [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

  •  ( … ) ” : Capturing group. Ex : B(arman|eer)
  •  (?: … ) ” : Non-capturing group. Ex: B(?:arman|eer)

Quantifiers

  • “ {3} “ : Exactly three times. Ex: d{3} -> 123, 321
  • “ ? ” : Preceding expression is optional (Matches 0 or 1 times).
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。