Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8995619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:38:38+00:00 2026-06-15T23:38:38+00:00

I’ve found a working solution to remove all html-tags as follow: <cfset test =

  • 0

I’ve found a working solution to remove all html-tags as follow:

<cfset test = rereplace(blah, "<h2[^>]*>", "", "ALL") />

I need to generate a xml file and rename some tags after they were formatted with XMLFormat().
Thus I tried the following:

<!--- example string --->
<cfset blah = '&lt;h1&gt;title 1&lt;/h1&gt;
               &lt;h2 style="color: black;"&gt;title 2&lt;/h2&gt;
               &lt;h3&gt;test&lt;/h3&gt;' />

<cfset test = rereplace(blah, "&lt;h2[^>]*&gt;", "<title_2>", "ALL") />

This changes my tag as I want, but it doesn’t stop at the > part?…
I also tried to escape the ampersand like this \&lt;h2[^>]*\&gt;, but that doesn’t seem to help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:38:39+00:00Added an answer on June 15, 2026 at 11:38 pm

    You cannot use > after you have formatted the XML, because that character no longer exists anywhere in the text.

    This will match/replace the opening h2 tag, but not the closing one:

    <cfset test = blah.replaceAll('&lt;h2((?:[^&]+|&(?!gt))*)&gt;','<title_2$1>') />
    

    The key part of that is: (?:[^&]+|&(?!gt))*

    Which matches either a non-ampersand character, or an ampersand not followed by gt, until it finds the end of the tag.

    To change the whole tag you need:

    <cfset test = blah.replaceAll('&lt;h2((?:[^&]+|&(?!gt))*)&gt;((?:[^&]+|&(?!lt;/h2))*)&lt;/h2&gt;','<title_2$1>$2</title_2>') />
    

    This repeats the same concept as above to also look for the closing h2 tag whilst capturing the contents to the appropriate groups.

    At this stage you’re starting to enter the territory of regex probably not being the best tool for the job – can you do these changes with an XML Parser prior to formatting it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Basically, what I'm trying to create is a page of div tags, each has
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.