我正在看正则表达式,比如我想判断字符串中是否含有 , ."
应该怎么做呢,我尝试了一个,但还有问题
String m="dfd.uei"
Pattern pattern= Pattern.compile("\\,|\\.|\\"")
Matcher isnum=pattern.matcher(m)
if(isnum.matches())
return true
else
return false 

解决方案 »

  1.   

    正则表达式写错了,应该是Pattern pattern= Pattern.compile(",|\\.|\"");
      

  2.   


    1:用contains函数
    2:String regex = ".*[\\.,\"].*";
      

  3.   

    Pattern pattern= Pattern.compile("[^\"\".,");
    Matcher isnum=pattern.matcher(m)
    if(isnum.matches())
    return false
    else
    return true
      

  4.   


    这个是正解。 . 需要转义,他是正则的通配符," 需要转义,他是是java的语法转义。
      

  5.   


    public static void main(String[] args) {
    String m="dfd.uei";
    Pattern pattern= Pattern.compile("\\,|\\.|\"");
    Matcher isnum=pattern.matcher(m);
    System.out.println(isnum.find());
    }
      

  6.   

    Pattern pattern= Pattern.compile("\\,|\\.|\"");
    ,:不用转义
    .:需要转义
    ":需要转义
      

  7.   

    you needn't use \ before every character.