Look-around assertions
Look-around assertions (positive look-ahead including) are zero-width checks. They really don’t consume anything from the input, but they let the regex engine backtrack if they are not satisfied.
Positive look-ahead remembers the position in input and tries to match from the current position to the right. If it does not match, regex engine backtracks, otherwise it returns to the remembered position in input and continues after the look-ahead.
The regex deconstructed
This regex consumes a comma and ensures, that the rest of input matches ([^\"]*\"[^\"]*\")*[^\"]*$
.
[^\"]
means “one character, not a double-quote”.*
means the previous character can be repeated zero or more times.- The parentheses form a group – it means “any string containing exactly two double-quotes, ending with one”.
- When
*
is applied on this group, it means “any string containing even number of double-quotes, ending with one”. - The “ending with one [double-quote]” part of description is problem, you don’t want such a constraint. So you append
[^\"]*
to provide possibility for non-double-quote characters. $
matches the end of string.
So all-in-all, the look-ahead checks if there is even number of double-quotes till the and of string after the comma.