I have a string,
String string = "sdeLING9497896,\"kifssd9497777 999_13\",Kfsheis9497896e,ersdG9497896,aseLING9497896 erunk15426 \nEsea4521
\"\nSdfes451 45264\" \"kiseliog949775 959_13\"";
I may have spaces, comma, tab or new line character in this string. My requirement is to split this string using space,comma,tab and new line but the spaces inside the double quoted strings should be excluded.
My sample code:
public class RegExTest {
public static void main(String[] args) {
Set<String> idSet = new HashSet<String>();
String string = "sdeLING9497896,\"kipliog9497777 999_13\",KIPLING9497896e,ersdG9497896,aseLING9497896 erunk15426 \nEsea4521 \"\nSdfes451 45264\"";
String ids[] = string.split(**"NEED A REGEX HERE"**);
for (String id : ids) {
if (id.trim().length() > 0) {
idSet.add(id);
}
}
System.out.println(idSet);
}
}
My expectation is: sdeLING9497896, kifssd9497777 999_13, KIPLING9497896e, ersdG9497896, aseLING9497896, erunk15426, Esea4521, Sdfes451 45264, kiseliog949775 959_13
Please guide me to solve this!