Pattern pattern = Pattern.compile("4$");
Matcher isMathe = pattern.matcher("1234564");
return isMathe.matches();为什么返回的是false???

解决方案 »

  1.   

    难道你想返回true??
    1234554和你的4$明显不匹配
      

  2.   

    Pattern pattern = Pattern.compile("^.*4$");
    Matcher isMathe = pattern.matcher("1234564");
    return isMathe.matches();
    这样就true了
      

  3.   

    Pattern pattern = Pattern.compile(".*4$");
    1234564整个是一个单词,所以4$匹配不上
      

  4.   


    Pattern pattern = Pattern.compile("4$");
    Matcher isMathe = pattern.matcher("1234564");
    System.out.println(isMathe.find());
    用find就行,不知道这2个函数有啥区别
      

  5.   


      Pattern pattern = Pattern.compile("[\\d]+4$");
         Matcher isMathe = pattern.matcher("13110420125");这样就能匹配
      

  6.   


    String str = "erei5394";
    第一种还来的快简单
    System.out.println("4".equals(str.substring(str.length()-1, str.length())));
    第二种就是用find
    Pattern pattern = Pattern.compile("4$");
    Matcher isMathe = pattern.matcher(str);        System.out.println(isMathe.find());
      

  7.   

    正则用这个:\d*4$
    此正则在EmEditor中测试能过