加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 01:41:50 所属栏目:百科 来源:网络整理
导读:Notation Description Example RE Symbols literal Match literal string value literal foo re1|re2 Match regular expressions re1 or re2 foo|bar . Match any character (except NEWLINE) b.b ^ Match start of string ^Dear $ Match end of string /bin

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)

datad+.txt

w

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

[A-Za-z_]w+

s

Match any whitespace character,same as [ ntrvf] (S is inverse ofs)

ofsthe

b

Match any word boundary (B is inverse of b)

bTheb

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读