【问题标题】:Regex to replace tr tag with th tag anywhere in html file正则表达式将 tr 标记替换为 html 文件中任何位置的 th 标记
【发布时间】:2010-05-21 08:43:47
【问题描述】:

在 HTML 文件中的任何位置,用th 标记替换tr 标记的正则表达式应该是什么?

【问题讨论】:

    标签: c# regex winforms


    【解决方案1】:
    Regex.Replace(html, @"(?<=<(/)?)th(?=[\s>])", "tr", RegexOptions.IgnoreCase);
    

    【讨论】:

    • +1。打败我。您还需要替换结束标签:Regex.Replace(strHTML, @"(?=[\s>])", "", RegexOptions.IgnoreCase);
    • @Didistis,它是否会替换html文件中任何有tr标签的所有th标签,无论是否有属性或任何东西?
    • new Regex("()", RegexOptions.IgnoreCase | RegexOptions.MultipleLine).Replace(html, m => m.Group[1].Value + "tr" + m.Group[3].Value);未测试...
    • @Didistis,对不起,我的错误,但我想替换 tr 标签而不是 th 标签。
    • @Harikrishna:只需交换它们:Regex.Replace(html, @"(?])", "th", RegexOptions .IgnoreCase);
    猜你喜欢
    • 2011-04-19
    • 1970-01-01
    • 2012-04-04
    • 2014-10-04
    • 2011-06-28
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多