0

How can I manipulate this code to run multiple Regex.Replaces on the same string?

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


        return strReplaceHtml;
    }
}

I attempted to stack the following but was unsuccessful:

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

1 Answer 1

1

I think you are close. Consider the following minor change to your code...

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

Good Luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.