locked
Help forming RegEx expression RRS feed

  • Question

  • Dear friends,

    I am new to RegEx and have a problem.

    I have an HTML string, for example:  "random html string <sp>superscript</sp> more random html"

    I want to remove the superscript tags and any text inside the superscript tag.

    I am using the following RegEx which is not working:

    ----
    RegEx = @"\<sup\>(\w\W)*\<\\sup\>"

    Explanation: \<sup\> --> match "<sup>"
                         (\w\W)* -> followed by any combination of characters
                         \<\\ -> denotes <\
                        sup\> -> sup>


    public string removeSuperscriptTags(string input)
            {

                return Regex.Replace(input, @"\<sup\>(\w\W)*<\\sup\>", "", RegexOptions.IgnoreCase);
            }

    The above code does nothing. Help is appreciated.

    Thanks.


    Dwight
    Tuesday, November 25, 2008 7:48 PM

Answers

  • I would use this:

    <sp([^>]*[^/])sp>

    You can also go to http://regexlib.com/ to search for similar items.

    There are 10 types of people in this world, those who understand Binary, and those who don't.
    • Marked as answer by Guo Surfer Friday, November 28, 2008 10:13 AM
    Tuesday, November 25, 2008 10:00 PM
  • One of the reasons your Regex does nothing is there is an error in it :) In the last part, you have "*<\\sup\>" when you wanted "*\</sup\>"
    Ron Whittle - If the post is helpful or answers your question, please mark it as such.
    • Marked as answer by Guo Surfer Friday, November 28, 2008 10:13 AM
    Wednesday, November 26, 2008 12:39 AM

All replies

  • I would use this:

    <sp([^>]*[^/])sp>

    You can also go to http://regexlib.com/ to search for similar items.

    There are 10 types of people in this world, those who understand Binary, and those who don't.
    • Marked as answer by Guo Surfer Friday, November 28, 2008 10:13 AM
    Tuesday, November 25, 2008 10:00 PM
  • One of the reasons your Regex does nothing is there is an error in it :) In the last part, you have "*<\\sup\>" when you wanted "*\</sup\>"
    Ron Whittle - If the post is helpful or answers your question, please mark it as such.
    • Marked as answer by Guo Surfer Friday, November 28, 2008 10:13 AM
    Wednesday, November 26, 2008 12:39 AM