java正则表达式

 

1

Regular ExpressionDescription
.Matches any character
^regexFinds regex that must match at the beginning of the line.
regex$Finds regex that must match at the end of the line.
[abc]Set definition, can match the letter a or b or c.
[abc][vz]Set definition, can match a or b or c followed by either v or z.
[^abc]When a caret appears as the first character inside square brackets, it negates the pattern. This can match any character except a or b or c.
[a-d1-7]Ranges: matches a letter between a and d and figures from 1 to 7, but not d1.
X|ZFinds X or Z.
XZFinds X directly followed by Z.
$Checks if a line end follows.

2

Regular ExpressionDescription
\dAny digit, short for [0-9]
\DA non-digit, short for [^0-9]
\sA whitespace character, short for [ \t\n\x0b\r\f]
\SA non-whitespace character, short for [^\s]
\wA word character, short for [a-zA-Z_0-9]
\WA non-word character [^\w]
\S+Several non-whitespace characters
\bMatches a word boundary where a word character is [a-zA-Z0-9_].

3

Regular ExpressionDescriptionExamples
*Occurs zero or more times, is short for {0,} X* finds no or several letter X,
.* finds any character sequence
+Occurs one or more times, is short for {1,} X+ - Finds one or several letter X
?Occurs no or one times, ? is short for {0,1}. X? finds no or exactly one letter X
{X}Occurs X number of times, {} describes the order of the preceding liberal \d{3} searches for three digits, .{10} for any character sequence of length 10.
{X,Y}Occurs between X and Y times, \d{1,4} means \d must occur at least once and at a maximum of four.
*? ? after a quantifier makes it a reluctant quantifier. It tries to find the smallest match. 

4

s.matches("regex")Evaluates if "regex" matches s. Returns only true if the WHOLE string can be matched.
s.split("regex")Creates an array with substrings of s divided at occurrence of "regex". "regex" is not included in the result.
s.replace("regex"), "replacement"Replaces "regex" with "replacement

 

 

 

 

 

 

 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值