I would like to split a character by spaces but keep the spaces inside the quotes (and the quotes themselves). The problem is, the quotes can be nested, and also I would need to do this for both single and double quotes. So, from the line this "'"is a possible option"'" and ""so is this"" and '''this one too''' and even ""mismatched quotes"
I would like to get [this, "'"is a possible option"'", and, ""so is this"", and, '''this one too''', and, even, ""mismatched quotes"]
.
This question has already been asked, but not the exact question that I'm asking. Here are several solutions: one uses a matcher (in this case """x"""
would be split into [""", x"""]
, so this is not what I need) and Apache Commons (which works with """x"""
but not with ""x""
, since it takes the first two double quotes and leaves the last two with x
). There are also suggestions of writing a function to do so manually, but this would be the last resort.