I'm having a lot of difficulty with spaces in Java while using regular expressions. The assignment is to split a comma-separated input string like,
J,Project report,"F, G, I",1
into separate strings containing:
J
Project report
F, G, I
1
if that makes sense. I'm using a Scanner to split the string. My regex (and code) I'm using is.
while (t.hasNext("([a-zA-Z0-9]| )*(\".+\")*,?")) {
System.out.println("t.next is : " + t.next());
...where t is a scanner of the input string as described above. But this does not appear to ever resort to true as nothing is printed. The closest I can get to working is just using simply ".*" as my regex, but that will separate at spaces and I need to separate only at the commas NOT within quotation marks. Can anyone assist? Thank you.