我想在字符串中分隔“/*”:
例如
String str="6666 /* 555 / 777 * ttt";
// And result should be
result= 6666 , 555 / 777 * ttt
我用
编写了程序String[] line_split=line_str.split("/*");
我收到此错误:
Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0 *
有人可以帮我解决吗?
最佳答案
String.split
使用Regex
进行分割。 *
是 Regex
中的元字符,具有特殊含义 - 匹配其前面的模式的 0 或多个
。
你需要转义:-
String[] line_split=line_str.split("/\\*");
关于java分隔符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13277211/