import java.util.regex .*;
Pattern p = Pattern.compile("ab\b");
Matcher m = p.matcher("frghab");
boolean b = m.matches();
怎么匹配不出来呢?用过的能解释一下\b怎么用吗?
Pattern p = Pattern.compile("ab\b");
Matcher m = p.matcher("frghab");
boolean b = m.matches();
怎么匹配不出来呢?用过的能解释一下\b怎么用吗?
Matcher m = p.matcher("frghab");
while(m.find()){
m.group(1);
}
匹配一个单词边界,也就是指单词和空格间的位置。例如, 'er\b' 可以匹配"never" 中的 'er',但不能匹配 "verb" 中的 'er'。
或者干脆
Pattern p = Pattern.compile("ab");
Pattern p = Pattern.compile("(.*ab\\b)");
Matcher m = p.matcher("frghab");
while(m.find()){
System.out.println(m.group(1));
}
Boundary matchers
^ The beginning of a line
$ The end of a line
\b A word boundary
\B A non-word boundary
\A The beginning of the input
\G The end of the previous match
\Z The end of the input but for the final terminator, if any
\z The end of the input
Pattern p = Pattern.compile("ab\\b");
Matcher m = p.matcher("frghab");
boolean b = m.matches(); ??????