"(?s)(?=(([^\"]+\"){2})*[^\"]*$)\\s+"
解释;
(?s) # This equals a DOTALL flag in regex, which allows the `.` to match newline characters. As far as I can tell from your regex, it's superfluous.
(?= # Start of a lookahead, it checks ahead in the regex, but matches "an empty string"(1) read more about that [here][1]
(([^\"]+\"){2})* # This group is repeated any amount of times, including none. I will explain the content in more detail.
([^\"]+\") # This is looking for one or more occurrences of a character that is not `"`, followed by a `"`.
{2} # Repeat 2 times. When combined with the previous group, it it looking for 2 occurrences of text followed by a quote. In effect, this means it is looking for an even amount of `"`.
[^\"]* # Matches any character which is not a double quote sign. This means literally _any_ character, including newline characters without enabling the DOTALL flag
$ # The lookahead actually inspects until end of string.
) # End of lookahead
\\s+ # Matches one or more whitespace characters, including spaces, tabs and so on
即复杂组在那里被重复两次将匹配空格在此字符串这是不以两种"
之间;
text that has a "string in it".
当与String.split一起使用时,将字符串拆分为; [text, that, has, a, "string in it".]
它只会匹配偶数"
,因此以下内容将匹配所有空格;
text that nearly has a "string in it.
分割串入[text, that, nearly, has, a, "string, in, it.]
(1)当我说一个捕获组匹配“空字符串”,我的意思是,它实际上抓住什么,它只是展望从点正则表达式,并检查一个条件,实际上没有捕获任何东西。实际的捕获是通过跟随前瞻的\\s+
完成的。
由于它会检查前面是否有偶数,如果输入中的引号没有正确配对,结果将是第一个报价将不会生效,并且配对将从第二个报价开始。 – nhahtdh
可能重复的[使用高级正则表达式在java中的字符串拆分](http://stackoverflow.com/questions/16655796/string-split-in-java-using-advanced-regex) – Anirudha