首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

【转】Dangling meta character '?' near index 0 错误的解决方法

2013-12-10 
【转】Dangling meta character ? near index 0 异常的解决办法Problem?转载自:http://www.javagalaxy.com

【转】Dangling meta character '?' near index 0 异常的解决办法

Problem?

转载自:http://www.javagalaxy.com/forum/viewtopic.php?p=377&sid=2d2152ff1ee06bc37c31b4b40e9a6fad

String str = "testing??";?

str = str.replaceAll("?", "");?

When you use the above pattern you get an exception as "Dangling meta character '?' near index 0"?


Solution?

String str = "testing??";?

str = str.replaceAll("\\?", "");?

You can use the above solution when you are replacing * and + symbols?

String str = "testing??*+";?

str = str.replaceAll("\\*", ""); //"Dangling meta character '*' near index 0"?
str = str.replaceAll("\\+", ""); //"Dangling meta character '+' near index 0"

?

+、*、|、/等符号在正则表达示中有相应的不同意义。
一般来讲只需要加[]、或是//即可

int i=s.split("[?]").length;

或者

int i=s.split("\\?").length;i);

热点排行