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 ^ means the beginning of a line, and (?<!...) is a negative look behind, so (?<!^) matches any position in the string that is not right at the beginning of the line.
The set [A-Z] matchies any capital letter, and (?=...) is a positive look ahead, so (?=[A-Z]) matches any position in the string that is right before a capital letter.
Put them together, and the expression matches any position in the string that is not right at the beginning of a line, and that is right before a capital letter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With