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
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