I need to split this string: "hello1\r\nhello2\r\n\r\nhello3\r\n\r\n\r\nhello4"
to: {"hello1\r\nhello2" , "hello3", "hello4"}
my code:
string text = "hello1\r\nhello2\r\n\r\nhello3\r\n\r\n\r\nhello4";
string[] wordsarray = Regex.Split(text, @"(\r\n){2,}");
The result is: {"hello1\r\nhello2" ,"\r\n" , "hello3" ,"\r\n" ,"hello4"}
What am I doing wrong?
You are very close. Simply use a non-capturing group:
Regex.Splitadds captured groups to the result array as described in “Remarks” section of Regex.Split.