常用的正则表达式一览

符号描述                                          例子(表达式)例子(匹配的字符串)                
 *

Matches the preceding character, subexpression, or bracketed character,
0 or more times

匹配0次或多次

a*b*aaaaaaaa,
aaabbbbb, bbbbbb        
 +

Matches the preceding character, subexpression, or bracketed character,
1 or more times

匹配1次或多次

a+b+aaaaaaaab,
aaabbbbb, abbbbbb 
 []

Matches any character within the brackets (i.e., “Pick any one of these
things”)

匹配中括号内的任何字符

[A-Z]*APPLE,
CAPITALS,
QWERTY
 ()

A grouped subexpression (these are evaluated first, in the “order of
operations” of regular expressions)

子表达式

(a*b)*aaabaab, abaaab,
ababaaaaab
 {m, n}

Matches the preceding character, subexpression, or bracketed character
between m and n times (inclusive)

匹配几遍

a{2,3}b{2,3} aabbb, aaabbb,
aabb 
 [^]

Matches any single character that is not in the brackets

取反 

[^A-Z]* apple,
lowercase,
qwerty 
 |

Matches any character, string of characters, or subexpression, separated
by the “I” (note that this is a vertical bar, or “pipe,” not a capital “i”)

或者(匹配其中的任何一个) 

b(a|i|e)d bad, bid, bed 
 .

Matches any single character (including symbols, numbers, a space, etc.)

匹配任意字符(包括字母,数字,空格,其他符号) 

b.d bad, b9d, bzd, b$d, b d 
 ^

Indicates that a character or subexpression occurs at the beginning of a
string

以XX开头 

^a apple, a9bp, asdf, a 
 \

An escape character (this allows you to use “special” characters as their
literal meaning)

使用特殊转义符 

\. \| \\ . | \ 
 $

Often used at the end of a regular expression, it means “match this up
to the end of the string.” Without it, every regular expression has a
defacto “.*” at the end of it, accepting strings where only the first part
of the string matches. This can be thougt of as analogous to the ^
symbol.

以XX结尾 

[A-Z]*[a-z]*$ ABCabc, zzzyx, Bob 
 ?!

“Does not contain.” This odd pairing of symbols, immediately preceding
a character (or regular expression), indicates that that character should
not be found in that specific place in the larger string. This can be tricky
to use; after all, the character might be found in a different part of the
string. If trying to eliminate a character entirely, use in conjunction with
a ^ and $ at either end.

不包含 

^((?![A-Z]).)*$ no-caps-here,
$ymb0ls a4e f!ne 

转载于:https://www.cnblogs.com/davidgu/p/4831357.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值