Skip to main content
Participant
July 9, 2010
Question

Is it possible to replace HTML tags?

  • July 9, 2010
  • 3 replies
  • 392 views

Say I have <span style = "font-weight:bold>Some text </span>. Is it possilbe to replace it with <i>Some text</i>? Would ReReplace accomplish this? There could possibly be multiple occurrances in the string.

    This topic has been closed for replies.

    3 replies

    Inspiring
    July 13, 2010

    Can you give us a couple of examples, especially of what you mean by "multiple occurances of the string?" Do you mean that the string might occur more than once between the <i> and </i> tag, or that <i>xyzzy</i> might occur more than once in the data?  Is the text that is initially between the <i> and </i> tags static, or is there a pattern to what it *always* looks like?  If it is static, then you will probably find it a lot simpler to just use a couple of replaceNoCase() calls.  You'll find that the regex works best if there is a definable pattern, otherwise you'll end up with a regex expression that is complex and harder to maintain that a couple of serial (or nested) replaceNoCase() calls. IMHO. Think in terms of the trade-off between a couple of split-seconds of execution time vs the amount of wall-clock time you spend wrestling with the regex every time the string between the <i> and </i> changes.

    -reed

    Inspiring
    July 9, 2010

    For that specific example, two replace tags would suffice.

    ilssac
    Inspiring
    July 9, 2010

    Yes, easily.

    But I would leave it to others more experienced with Regex to sugest actual syntax.

    But I find this a very useful site when I'm figureing out my own - http://www.regular-expressions.info/reference.html

    Multipe occurances are easily handled with the "ALL" parameter of the reReplace() function.