[英]Regex pattern in Java. Fix semicolons
i wrote Regex .*?(?=;)|(?<=;).*
which have to take values between semicolons. 我写了Regex
.*?(?=;)|(?<=;).*
必须在分号之间取值。 My text: 2014-01-01 00:01:00;;16;4;0;0;1
. 我的文字:
2014-01-01 00:01:00;;16;4;0;0;1
。 Actual it parsing string to this: 实际将其解析为:
[2014-01-01 00:01:00, , , 16, , 4, , 0, , 0, , 1]
. [2014-01-01 00:01:00, , , 16, , 4, , 0, , 0, , 1]
。
It replaces semicolons to spaces, which is unwanted feature of course, how to fix it ? 它将分号替换为空格,这当然是不需要的功能,如何解决?
Just do splitting on one or more semi-colons. 只需拆分一个或多个分号即可。
string.split(";+");
or 要么
Match any character but not of ;
匹配任何字符,但不匹配
;
one or more times. 一或多次。
Pattern.compile("[^;]+");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.