正则表达式 笔记
Yuxuan Wu Lv13

正则表达式大全

\ Used to drop the special meaning of character following it (discussed below)

[] Represent a character class

^ Matches the beginning

$ Matches the end

. Matches any character except newline

? Matches zero or one occurrence.

| Means OR (Matches with any of the characters separated by it.

* Any number of occurrences (including 0 occurrences)

+ One or more occurrences

{} Indicate number of occurrences of a preceding RE

to match.

() Enclose a group of REs

\d Matches any decimal digit, this is equivalent to the set class [0-9].

\D Matches any non-digit character.

\s Matches any whitespace character.

\S Matches any non-whitespace character

\w Matches any alphanumeric character, this is equivalent to the class [a-zA-Z0-9_].

\W Matches any non-alphanumeric character.

  • 字符和.字符搭配可以匹配所有的字符. 匹配所有字符
  • 任何对象都可以被用来在if或者是while条件中检测真假。

下面展示的是大多数内置的对象被认为是false的情形:

constants defined to be false: None, False

zero of any numeric type: 0, 0.0, 0j, Decimal(0), Fraction(0,1)

empty sequences and collections: ‘’,(),[],{}, set(), range(0)

注意r里面的转义符号\这才是,巨坑

https://www.jianshu.com/p/d56afe14835b

  • Post title:正则表达式 笔记
  • Post author:Yuxuan Wu
  • Create time:2021-03-25 23:23:32
  • Post link:yuxuanwu17.github.io2021/03/25/2021-03-26-正则表达式-笔记/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.