This question already has an answer here:
- Splitting a nested string keeping quotation marks 3 answers
I'm looking for regex to do the following in Java:
String originalString = "";
String splitString[] = originalString.spilt(regex);
Some test cases:
Original1: foo bar "simple"
Spilt1: { "foo", "bar", "\"simple\"" }
Original2: foo bar "harder \"case"
Spilt2: { "foo", "bar", "\"harder \"case\"" }
Original3: foo bar "harder case\\"
Spilt3: { "foo", "bar", "\"harder case\\"" }
Some snippets I have come across:
# Does not react to escaped quotes
(?=([^\"]*\"[^\"]*\")*[^\"]*$)
# Finds relevant quotes that surround args
(?<!\\)(?:\\{2})*\"
Thanks!