简体   繁体   中英

Tokenize string in java using regular expression

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.

(\\([^)]+\\))|([^ ]+)

解释和用法在这里

以下正则表达式解决了目的:

(\\([^)]+\\))|([^ \"]*\"[^\"]*\")|([^ ]+)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM