import java.util.regex .*;
Pattern p = Pattern.compile("ab\b");
 Matcher m = p.matcher("frghab");
 boolean b = m.matches(); 
怎么匹配不出来呢?用过的能解释一下\b怎么用吗?

解决方案 »

  1.   

    Pattern p = Pattern.compile("ab\b");
     Matcher m = p.matcher("frghab");
     while(m.find()){
    m.group(1);
    }
      

  2.   

    \b
    匹配一个单词边界,也就是指单词和空格间的位置。例如, 'er\b' 可以匹配"never" 中的 'er',但不能匹配 "verb" 中的 'er'。
      

  3.   

    Pattern p = Pattern.compile("ab$");
    或者干脆
    Pattern p = Pattern.compile("ab");
      

  4.   

    我弄了个串 "erersdfderdfaser" 去匹配 "er\b" 什么显示都没有
      

  5.   

    不好意思啊,试一下这个,可以的:
    Pattern p = Pattern.compile("(.*ab\\b)");
     Matcher m = p.matcher("frghab");
     while(m.find()){
      System.out.println(m.group(1));
    }
      

  6.   

    \b  是有意义的,我英语不好,大家看看这是什么意思。
    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 
      

  7.   

    import java.util.regex .*;
    Pattern p = Pattern.compile("ab\\b");
     Matcher m = p.matcher("frghab");
     boolean b = m.matches(); ??????