簡體   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