• 正则表达式是大小写敏感的

Hello

Hello, world!

hello, world!

  • 空格、缩进或换行都会影响匹配结果

Hello, world!

Hello, world!

Hello,world!

  • ^和$

^who

who is who

who$

who is who

  • ^、$和\需要转义

^$

$12$ \\-\ $25$

\$

$12$ \\-\ $25$

\$$

$12$ \\-\ $25$

\\\\

$12$ \-\ $25$

  • .匹配任意一个字符

.

Regular expressions are powerful!!!

……

Regular expressions are powerful!!!

  • .同样需要转义

.

O.K.

\\.

O.K.

\\..\\.

O.K.

  • 一系列字符被[]包含

[oyu]

How do you do?

[dH].

How do you do?

[owy][yow]

How do you do?

  • [C-K]等价于[CDEFGHIJK],[C-Ka-d2-6]等价于[CDEFGHIJKabcd23456]

  • [^CDghi45]与[CDghi45]匹配方式相反,[^W-Z]与[W-Z]匹配方式相反

  • 一系列字符串被()包含,被|分隔

(on|ues|rida)

Monday Tuesday Friday

(Mon|Tues|Fri)day

Monday Tuesday Friday

..(id|esd|nd)ay

Monday Tuesday Friday

参考资料

Regular Expressions Tutorial