Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Is it possible to replace HTML tags?

Community Beginner ,
Jul 09, 2010 Jul 09, 2010

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.

364
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 09, 2010 Jul 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2010 Jul 09, 2010

For that specific example, two replace tags would suffice.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 13, 2010 Jul 13, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources