This pushes the edge a bit, but I have the following situation with this regular expression - "()": when used to split a string into an array [], the results are somewhat strange to me. For example, this line of code:
string[] res = new Regex("()").Split("hi!");
sets res to an array of 9 (!) elements: ["," "," h ",", "i", ","! ",", ""]
I expect it to return these 5 elements: ["h", "," i ",", "!" ]. The reason I need this particular result is compatibility with another regexp library ...
My question is, can this behavior be related to some missing parameters of the regex object or to some kind of coding problem or similar ... Or is it determined in some way and, of course, is the correct way it should work? Also, is there a way to get it to return a second (expected) result?
source share