我有一个关于 Java 中的 Regex 的快速问题(尽管其他语言可能相似)。
我想要做的是像这样转换一个字符串:
How are you "Doing well" How well 10 "That's great"
//# I want the Regex in Java to match out all of the words, numbers,
//# and things inside quotation marks. Ideally, I'd get something like this
How
Are
You
"Doing Well"
How
Well
10
"That's Great!"
我尝试使用的正则表达式如下:
String RegexPattern = "[^"+ // START_OR: start of line OR"
"\\s" + // empty space OR
"(\\s*?<=\")]" + // ENDOR: preceeded by 0 or more spaces and a quotation mark
"(\\w+)" + // the actual word or number
"[\\s" + // START_OR: followed by a space OR
"(?=\")" + // followed by a quotation mark OR
"$]"; // ENDOF: end of line
不过,这对我不起作用;即使是更简单的字符串!我花了很多时间在这里寻找类似的问题。如果我不需要引号,我可以使用拆分;但最终,这种模式会变得更加复杂,所以我需要使用正则表达式(这只是第一次迭代)。
我会很感激任何帮助;提前致谢!