正则表达式速查 java

== java.util.regex
(-|\\+)?\\d+ // +911 // -1234

--- character classes
in java code (\ == \\)
\xhh // 0xhh character
\uhhh // 0xhhhh unicode character
\t // tab
\n // new line
\r // carriage return
\f // form feed
\e // escape
. // any character
[abc] // a|b|c (or)
[^abc] // except a,b,c (negation)
[a-zA-Z] // a through z or A through Z (range)
[abc[hij]] // same [abchij] (union)
[abc&&[hij]] // abc&&hij == hij (intersection)
\s // whitespace (space,tab,newline,form feed,carriage return)
\S // non-whitespace [^\s]
\d // numeric digit [0-9]
\D // non-digit [^0-9]
\w // word character [a-zA-Z_0-9]
\W // non-word character [^\w]

--- logical operators
XY // X followed Y
X|Y // X or Y
(X) // a caturing group.You can refer to the (i)th captured group later in ther experssion with \i.

--- boundary mathers
^ // Beginning of a line
$ // End of a line
\b // Word boundary
\B // Non-word boundary
\G // End of the previous match

--- Greedy Reluctant Possessive
X{n} // default Greedy 尽可能多
X{n}? // ? Reluctant 尽可能少
X{n}+ // + Possessive 占有的 (防止回溯)

--- pattern & matcher
String regexStr="\\d+";
Pattern p=Pattern.compile(regexStr)
Matcher m=p.matcher(txt);
while(m.find()) print(m.group());

--- groups
A(B(C))D
// groups
0 ABCD
1 BC
2 C

--- Pattern flags
CANON_EQ 默认模式
(?i) CASE INSENSITIVE 大小写不敏感(ASCII)
(?x) COMMENTS 忽略多余的空格和#开始的注释
(?s) DOTALL .包含行终止符
(?m) MULTILINE 多行 ^$
(?u) UNICODE CASE 大小写不敏感 unicode
(?d) UNIX LINES

--- operator
split
replaceFirst
replacement
replaceAll
reset



== Formatter String.format
%-15.2f
d integral,c unicode character,b boolean,s string,f float,e float,x integral(hex),h hash code,% %,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值