正则表达式中最常见的符号和字符

Notation

Description

Example RE

Symbols



literal

Match literal string valueliteral

foo

re1|re2

Match regular expressionsre1 or re2

foo|bar

.

Matchany character (except NEWLINE)

b.b

^

Match start of string

^Dear

$

Match end of string

/bin/*sh$

*

Match 0 or more occurrences of preceding RE

[A-Za-z0-9]*

+

Match 1 or more occurrences of preceding RE

[a-z]+\.com

?

Match 0 or 1 occurrence(s) of preceding RE

goo?

{N}

Match N occurrences of preceding RE

[0-9]{3}

{M,N}

Match from M to N occurrences of preceding RE

[0-9]{5,9}

[...]

Match any single character fromcharacter class

[aeiou]

[..x-y..]

Match any single character in therange fromx to y

[0-9],[A-Za-z]

[^...]

Do not match any character from character class, including any ranges, if present

[^aeiou], [^A-Za-z0-9_]

(*|+|?| {})?

Apply "non-greedy" versions of above occurrence/repetition symbols (*,+, ?, {})

.*?[a-z]

(...)

Match enclosed RE and save assubgroup

([0-9]{3})?, f(oo|u)bar

Special Characters



\d

Match any decimal digit, same as [0-9](\D is inverse of \d: do not match any numeric digit)

data\d+.txt

\w

Match any alphanumeric character, same as [A-Za-z0-9_] (\W is inverse of\w)

[A-Za-z_]\w+

\s

Match any whitespace character, same as [ \n\t\r\v\f] (\S is inverse of\s)

of\sthe

\b

Match any word boundary (\B is inverse of \b)

\bThe\b

\nn

Match saved subgroup nn (see (...) above)

price: \16

\c

Match any special character c verbatim (i.e., with out its special meaning, literal)

\., \\, \*

\A (\Z)

Matchstart (end) of string (also see ^ and $ above)

\ADear


REF:Core Python Programming

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值