replaceAll(String regex,String replacement)replaceAll("?:","??")

解决方案 »

  1.   

    wswhp(greenland) ,这么做会出错阿
    java.util.regex.PatternSyntaxException : Dangling meta character '?' near index 0  ?:
      

  2.   

    public static void main(String args[]) throws Exception{
    String str = "sadf?:sdf??sdf";
    str = str.replaceFirst("?:","k");
    System.out.println(str);
    }出错,帮我看看错在那里?
      

  3.   

    class  Replaces
    {
    public static void main(String args[]) throws Exception{
    String str = "sadf?:sdf??sdf";
    str = str.replaceFirst("?:","k");
    System.out.println(str);
    }
    }
    这个没错,确定你引用的是java.lang.String.replaceFirst而不是java.util.regex.Matcher.replaceFirst
      

  4.   

    可是都是错的阿,你试了吗?
    public static void main(String args[]) throws Exception{
    String str = "sadf?:sdf??sdf";
    str = str.replaceFirst("?:","k");
    System.out.println(str);
    }
    public static void main(String args[]) throws Exception{
    String str = "sadf?:sdf??sdf";
    str = str.replaceAll("?:","k");
    System.out.println(str);
    }
    都抛了异常
      

  5.   

    cool,又学到一手,不过为什么啊,是因为?:和regax的语法冲突吗?为什么要改成\\?:,还有别的什么东西也会碰到这种情况而要改呢?