I spent like three hours trying to understant how does "(?<!^)(?=[A-Z])" works to split at tring according to capital letters i.e.
string[] s = Regex.Split("TheWorldWithoutStrangers", "(?<!^)(?=[A-Z])");
How does it work !! I do understand what is the meaning of each char in the above expression, but I do not get how does it work together. why "(? < !^)([A-Z])" doesnot work ? it means that whenever you find a captial letter that is not after a new line, then split, am I right ?
The key here is that the two parts
(?<!...)and(?=...)are zero-width assertions. The first one makes sure^(start of string) does not occur right before the match position and the second one ensures that[A-Z](single capital letter) appears right after the match position. The actual match is empty because neither of the assertions actually match any characters. The entire expression merely matches a position.