请教一个关于replace字符串的问题 replaceAll(String regex,String replacement)replaceAll("?:","??") 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 wswhp(greenland) ,这么做会出错阿java.util.regex.PatternSyntaxException : Dangling meta character '?' near index 0 ?: public static void main(String args[]) throws Exception{ String str = "sadf?:sdf??sdf"; str = str.replaceFirst("?:","k"); System.out.println(str); }出错,帮我看看错在那里? 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 可是都是错的阿,你试了吗? 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); }都抛了异常 cool,又学到一手,不过为什么啊,是因为?:和regax的语法冲突吗?为什么要改成\\?:,还有别的什么东西也会碰到这种情况而要改呢? 关于线程间通信的例子(PipedStream)请高手帮忙看看 java调用PowerBuilder生成的EXE GUI中 怎样设置界面显示的风格 具体使用哪个类? 感谢各位指导! 帮忙下 请教:怎么用java画箭头? 得到路径后,怎么在路径后面+"\"? java中文问题:如何从中文编码得到中文? 用jb怎么在另一个类中控制frame中的一个label的text的实时的变化?多谢 会者不难 怎样把byte[]的内容置空 急!急! 关于字体的问题 java学到什么时候,可以找到好的工作?
java.util.regex.PatternSyntaxException : Dangling meta character '?' near index 0 ?:
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.replaceFirst("?:","k");
System.out.println(str);
}
}
这个没错,确定你引用的是java.lang.String.replaceFirst而不是java.util.regex.Matcher.replaceFirst
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);
}
都抛了异常