What I have
string ImageRegPattern = @"http://[\w\.\/]*\.jpg|http://[\w\.\/]*\.png|http://[\w\.\/]*\.gif";
string a ="http://www.dsa.com/asd/jpg/good.jpgThis is a good dayhttp://www.a.com/b.pngWe are the Best friendshttp://www.c.com";
What I want
string[] s;
s[0] = "http://www.dsa.com/asd/jpg/good.jpg";
s[1] = "This is a good day";
s[2] = "http://www.a.com/b.png";
s[3] = "We are the Best friendshttp://www.c.com";
Bouns:
if the url can be splited like below, it will be better, but if not, that's ok.
s[3] = "We are the Best friends";
s[4] = "http://www.c.com";
What's the question
I try to use the code below to split the string,
string[] s= Regex.Split(sourceString, ImageRegPattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
But the result is not good, it seems that the Split method take out all the strings which matched the ImageRegPattern. But I want them to stay. I check the RegEx page on MSDN ,it seems there is no proper method to meet my need. So how to do it?
Regex.Split("1,2,3", ",")will return the array["1","2","3"]. The pattern you supply defines the separator, not what you want to keep.Regex.Splitis not what you want to use here. You're trying to keep the text and the separators, which is not whatSplitdoes.