繁体   English   中英

C#多个正则表达式替换

[英]C# Multiple Regex Replace

如何处理此代码以在同一字符串上运行多个Regex.Replaces?

public static class StringExtensions
{
    public static string SkipImgTags(this string html, int length)
    {
        string strReplaceHtml = Regex.Replace(html, @"(< *?/*)strong( +?|>)", @"(< *?/*)bold( +?|>)", RegexOptions.IgnoreCase);


        return strReplaceHtml;
    }
}

我尝试堆叠以下内容,但未成功:

string strReplaceHtml = Regex.Replace(html, @"(< *?/*)strong( +?|>)", @"(< *?/*)bold( +?|>)", RegexOptions.IgnoreCase);
string strReplaceHtml = Regex.Replace(html, @"(< *?/*)em( +?|>)", @"(< *?/*)italic( +?|>)", RegexOptions.IgnoreCase);

我觉得你很亲密。 请考虑对您的代码进行以下较小更改...

string strReplaceHtml = Regex.Replace(html, @"(< *?/*)strong( +?|>)", @"(< *?/*)bold( +?|>)", RegexOptions.IgnoreCase);
strReplaceHtml = Regex.Replace(strReplaceHtml , @"(< *?/*)em( +?|>)", @"(< *?/*)italic( +?|>)", RegexOptions.IgnoreCase);

祝好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM