要匹配html内容
我在找的内容如下
<tr></tr> 中的内容 里面的数据不规格,但是只有<td></td> or <td>数据<td></td>数据</td>
有什么规则提取<tr></tr> 中的内容
我在找的内容如下
<tr></tr> 中的内容 里面的数据不规格,但是只有<td></td> or <td>数据<td></td>数据</td>
有什么规则提取<tr></tr> 中的内容
解决方案 »
- 用ApplicationClass导出excel,使用了Quit,但为什么excel.exe进程不会自己关闭?
- C# 默认值问题
- 大虾们帮我看看 哪错了啊 求1000以内的素数
- 谁能给我讲讲vs05水晶报表的命令怎么用
- 如何将程序打包生成安装程序
- 程序在没有编译环境的win2003中不能运行!这是怎么回事?
- 如何取得ListView选中的列的字段?????
- 请教一个winform权限验证的一些问题
- vc6中写dll可以让其他语言调用,那么c#写的dll能让其他语言调用吗?问题的答案找不到(英文水平一般)
- image 类型的显示
- C# 如何编程实现背景橡皮擦
- XML 反序列化的时候如何识别是哪个对象??????
string str = "...";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"(?<=<tr>)(?<content>[^</tr>]*)(?=</tr>)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.MatchCollection m = reg.Matches(str); //设定要查找的字符串
for (int i = 0; i < m.Count; i++)
{
Response.Write(m[i].Groups["content"].ToString());
}
MatchCollection mc = Regex.Matches(yourStr,@"(?is)<tr[^>]*>(?><tr[^>]*>(?<b>)|</tr>(?<-b>)|(?:(?!</?tr\b).)*)*(?(b)(?!))</tr>")
foreach(Match m in mc)
{
MessageBox.Show(m.Value);
}
private void TestRegex31()
{
string yourStr = "<tr>fdafdasfdats</tr>";
MatchCollection mc = Regex.Matches(yourStr, @"(?is)(?<=<tr[^>]*>)(?><tr[^>]*>(?<b>)|</tr>(?<-b>)|(?:(?!</?tr\b).)*)*(?(b)(?!))(?=</tr>)");
foreach (Match m in mc)
{
MessageBox.Show(m.Value);
}
}
string str= "1111<tr>2222</tr>3333";
Match match1 = Regex.Match(str, @"<tr>(?<key>.*)</tr>", RegexOptions.IgnoreCase);
string result = match1.Groups["key"].Value;
结果 result= "2222";
这样不合适,比如:<tr>123</tr><tr>456></tr>
你的Result="123</tr><tr>456>"
^_^你的没考虑嵌套
<tr>aaa<tr>bbbb</tr>aaa</tr>
你的返回就成
<tr>aaa<tr>bbbb</tr>这样了。