import java.util.regex.*;public class bbb {
static String xx = "123123";
public static void main(String[] args) {
Pattern p = Pattern.compile("/123/");
Matcher m = p.matcher(xx);
boolean b = m.find();
System.out.print(b);
}
}为什么我总返回false呢?谢谢大家先。

解决方案 »

  1.   

    Pattern p = Pattern.compile("123"); /去了
      

  2.   

    import java.util.regex.*;public class bbb {
    static String xx = "123123";
    public static void main(String[] args) {
    Pattern p = Pattern.compile("123");  //不需要反斜杠,因为""不是要匹配的字符.
    Matcher m = p.matcher(xx);
    boolean b = m.find();
    System.out.print(b);
    }
      

  3.   

    你的""引号不是字符串,不用转义的如:
    System.out.println("aaab")
    结果是aabb
    而:
    System.out.println("/"aaab/"")
    结果是"aabb"
      

  4.   

    这JAVA做的真厉害,所有的工作都在包里面了
      

  5.   

    API中这么写的,只有在输入的字符串(或其字串)和模式匹配才返回真。你的模式是“/123/”当然返回false
    Returns:
    true if, and only if, a subsequence of the input sequence matches this matcher's pattern
      

  6.   

    忘了写,是find()方法的返回值