通过正则表达式 读取数据

Regex reg = new Regex( " (? <= <div [^>]*>)((?!品种代码)[^ <])+(?= </div>) " , RegexOptions.IgnoreCase);
foreach (Match m in reg.Matchs(str))
{
Console.WriteLine(m.Value);
}


string pattern="<tr [^>]*>\s*<td [^>]*>(?<type>[^<]*)</td>\s*<td [^>]*>(?<open>[^<]*)</td>\s*<td [^>]*>(?<high>[^<]*)</td>\s*<td [^>]*>(?<low>[^<]*)</td>\s*<td [^>]*>(?<close>[^<]*)</td>\s*<td [^>]*>(?<nowprice>[^<]*)</td>\s*<td [^>]*>(?<balance>[^<]*)</td>\s*<td [^>]*>(?<trade>[^<]*)</td>\s*<td [^>]*>(?<count>[^<]*)</td>\s*<td [^>]*><font [^>]*>(?<addcount>[^<]*)</font></td>\s*</tr>";
Regex reg
=new Regex(pattern);
foreach(Match m in reg.Matches(str))
{
Console.WriteLine(m.Group[
"type"].Value);
Console.WriteLine(m.Group[
"open"].Value);
Console.WriteLine(m.Group[
"high"].Value);
Console.WriteLine(m.Group[
"low"].Value);
Console.WriteLine(m.Group[
"close"].Value);
Console.WriteLine(m.Group[
"nowprice"].Value);
Console.WriteLine(m.Group[
"balance"].Value);
Console.WriteLine(m.Group[
"trade"].Value);
Console.WriteLine(m.Group[
"count"].Value);
Console.WriteLine(m.Group[
"addcount"].Value);
}

你可能感兴趣的:(正则表达式)