Reputation: 1568
I have input String in following format:
"xyz PQ (All) (foo \"(abc\" def) test \"elasticSearch\" (test \"pqr\" stu) "
I want to tokenize it such that the string should be split by space excluding double quotes and parentheses, so it should give below result
xyz
PQ
All
foo "(abc" def
test
"elasticSearch"
test "pqr" stu
Any help would be appreciated.
Upvotes: 2
Views: 61
Reputation: 1568
following regex solves the purpose:
(\\([^)]+\\))|([^ \"]*\"[^\"]*\")|([^ ]+)
Upvotes: 1