<body> <div id="wrapper"> <div id="CSDNPHL"> 
<table class="CSDN-PHF" border="0" cellspacing="1" cellpadding="0"> 
<tr> </tr> <
/table> </div> <div id="mainWrapper"> 
<table border="0" cellpadding="0" cellspacing="1">
 <tr> <td colspan="2" class="pageCaption"> 欢迎 <dfn> chinesesunmt () </dfn> 来CSDN发表新话题 </td> </tr> <tr> <td class="left"> 相关问题: </td> <td> <dl id="relationTopic"> <dt> 输入问题,问题答案立即呈现在您眼前! </dt> <dd id="relationList"> </dd> </dl> </td> </tr> </tr> </table> </body> 正则表达式:
<table ([^>]*)用C#执行,结果为:
1.位置:46,长度:66
<table class="CSDN-PHF" border="0" cellspacing="1" cellpadding="0"
  组1. 位置:53,长度:59:  class="CSDN-PHF" border="0" cellspacing="1" cellpadding="0"2.位置:167,长度:49
<table border="0" cellpadding="0" cellspacing="1"
  组1. 位置:174,长度:42:  border="0" cellpadding="0" cellspacing="1"

解决方案 »

  1.   

    using System.Text.RegularExpressions;
    -------
    RegexOptions options =RegexOptions.IgnoreCase;
    string pattern = "<table([^> ]*)";
    string src="要提取的源字符串";
    MatchCollection matches = Regex.Matches(src, pattern, options);
    foreach (Match match in matches)
    {
        Console.WriteLine(match.Value);
        foreach (Group group in match.Groups){
            Console.WriteLine(group.Value); // group就是正则表达式里用()括起来的部分
        }
    }