[英]How can i remove this string split problem in java?
I have a String like this in my Java Program我的 Java 程序中有这样的字符串
String str = ("System.out.print(Numerator?)int");
And i hava a delimiter to split the element我有一个分隔符来分割元素
private static final String DELIMITER = "\"(?:\\\\\"|[^\"])*?\"|[\\s.,;:+*/|!=><@?#%&(){}\\-\\^\\[\\]\\&&]+|int";
and print out并打印出来
for (String retval: str.split(DELIMITER)){
System.out.println(retval);
}
but the output is但 output 是
System
out
pr
Numerator
i want the output is我想要 output 是
System
out
print
Numerator
How to fix it by only split the "int" not pr"int".如何通过仅拆分“int”而不是 pr“int”来修复它。
Alternative:选择:
See context:查看上下文:
public static void main(String[] args) {
String input = ("System.out.print(Numerator?)int");
List<String> elements = Pattern.compile("\\W|\\bint\\b").splitAsStream(input).collect(Collectors.toList());
elements.forEach(System.out::println);
}
Output: Output:
System
out
print
Numerator
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.