I am planning to split a string in java using regex. My input will be as follows
2010-11-10 00:00:00,999, some string follows
I am using
inputString.split("(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3},)");
This gives a string[] with two elements, second element is “some string follows” but first element is empty string, how to get the first part of the string.
Update: I cant assume the date will be at the beginning. Sorry for leaving it out earlier.
You probably don’t want split. Split’s argument is the delimited between the strings. So you are succesfully matching the timestamp, but split is returning you the string before that (empty) and after (“some string follows”).
You probably want
(untested!)