"(?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
2 回繰り返される複雑なグループは、2 つの間にないこの文字列の空白に一致します"
。
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+
、先読みに従うことによって行われます。