如何替换html广西中的标签?谢谢。
要将下面的文档:
<table border="1" width="100%" style="border-collapse: collapse">
<tr>
<td>[L1.c.sub{1}.r{1}.title{66}]</td>
<td>[L1.c.sub{1}.r{2}.title{77}]</td>
</tr>
<tr>
<td>[L1.c.sub{2}.r{1}.title{88}]</td>
<td>[L1.c.sub{2}.r{2}.title{99}]</td>
</tr>
</table>
替换成:
<table border="1" width="100%" style="border-collapse: collapse">
<tr>
<td>L1csub-1  reco-1  titlelen-66</td>
<td>L1csub-1  reco-2  titlelen-77</td>
</tr>
<tr>
<td>L1csub-2  reco-1  titlelen-88</td>
<td>L1csub-2  reco-2  titlelen-99</td>
</tr>
</table>
应该怎么做?谢谢。

解决方案 »

  1.   

    我写的这个匹配楼主所给的例子没问题,但是并不一定能用,要看楼主在实际用时是否有其它情况,或是限定条件了,如果有匹配不成功的,楼主把文档贴出来,再说明一下限定条件string resultStr = Regex.Replace(yourStr, @"<td>\[(.*?)\.(\w)\.(.*?)\{(\d+)}\.r\{(\d+)}\.(.*?)\{(\d+)}\]</td>","<td>$1$2$3-$4  reco-$5  $6len-$7</td>" , RegexOptions.IgnoreCase);
      

  2.   

    不太清楚你要什么 随便写了一个
    rule = @"\[L1\.c\.sub\{(\d+)\}\.r\{(\d+)\}\.title\{(\d+)\}\]";
    结果 = Regex.Replace(查询串,"L1csub-$1  reco-$2  titlelen-$3",rule,RegexOptions.IgnoreCase);
      

  3.   

    string yourStr = ......;
    string resultString = Regex.Replace(yourStr, "<td>\\[(.+?)\\.(.+?)\\.(.+?){(.+?)}\\..+?{(.+?)}\\..+?{(.+?)}]</td>", "<td>$1$2$3-$4 reco-$5 titlelen-$6</td>", RegexOptions.IgnoreCase);
      

  4.   

    string yourStr = ......;
    string resultString = Regex.Replace(yourStr, @"\[L1\.c\.sub{(\d+?)}.r{(\d+?)}\.title{(\d+?)}\]", "L1csub-$1  reco-$2  titlelen-$3", RegexOptions.IgnoreCase);