Regex pattern in Java. Fix semicolons

i wrote Regex .*?(?=;)|(?<=;).* which have to take values between semicolons. My text: 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].

It replaces semicolons to spaces, which is unwanted feature of course, how to fix it ?

Upvotes: 1

Views: 64

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174786

Just do splitting on one or more semi-colons.

string.split(";+");

or

Match any character but not of ; one or more times.

Pattern.compile("[^;]+");

Upvotes: 1

Related Questions