Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Sunday, May 14, 2006

C# regular expression code snippet

Problem in www.csdn.net: to extract text between and
Solution given by masterz:
String regex_pattern = @"<font([^<]+)>(?<word>[^<]+)</font>";
String source_string = @"<font color=#0000cc class=bb>程序员网站</font>阿瑟毒发斯多夫<font color=#0000cc class=bb>你好</font>";
Regex html_regex = new Regex(regex_pattern);
Match m = html_regex.Match(source_string);
while(m.Success && m != null)
{
System.Windows.Forms.MessageBox.Show(m.Groups["word"].Value);
m = m.NextMatch();
}
//by Onega (www.fruitfruit.com) via VC# 2005

0 Comments:

Post a Comment

<< Home