public static void main(String agrs[]){
Pattern pattern = Pattern.compile("\ba\b"); 
Matcher m = pattern.matcher("There is a dog");
System.out.println(m.find());
}
为什么会没有匹配呢? \b到底什么意思啊.不是很明白这个....

解决方案 »

  1.   

    Word boundary tokens:\ba\bPattern pattern = Pattern.compile("\\ba\\b"); 
    Matcher m = pattern.matcher("There is a dog");
    System.out.println(m.find());
      

  2.   

    用来确定一个单词的界限,比如说你要搜索 the,有一个句子是,these are the apples. 如果不用\b,正则表达式会返回,these和the.如果是运用\bthe\b就只会返回the。