(?!^)
is a regular expression consisting of a negative lookahead. ^
is an anchor used to signify the start of the string. (?!^)
matches all 0-length strings that are not followed by ^
, the start of the string. In other words, it matches all 0-length strings except that at the start of the string.
For example, in the string abc
, there will be 3 matches: one between a
and b
, one between b
and c
, and one after the c
. Splitting on these matches produces the desired array (note that the 1-argument version of split()
discards any trailing empty strings, which is why none are included in the resulting array).