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 927329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:50:01+00:00 2026-05-15T19:50:01+00:00

I have a html source as a String variable. And a word as another

  • 0

I have a html source as a String variable.
And a word as another variable that will be highlighted in that html source.

I need a Regular Expression which does not highlights tags, but obly text within the tags.

For example I have a html source like

<cfset html =  "<span>Text goes here, forr example it container also **span** </span>" />
<cfset wordToReplace = "span" />
<cfset html = ReReplace(html ,"[^(<#wordToReplace#\b[^>]*>)]","replaced","ALL")>

and what I want to get is

<span>Text goes here, forr example it container also **replaced** </span>

But I have an error. Any tip!

  • 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-05-15T19:50:02+00:00Added an answer on May 15, 2026 at 7:50 pm

    I need a Regular Expression which does
    not highlights tags, but obly text
    within the tags.

    You wont find one. Not one that is fully reliable against all legal/wild HTML.

    The simple reason is that Regular Expressions match Regular languages, and HTML is not even remotely a Regular language.

    Even if you’re very careful, you run the risk of replacing stuff you didn’t want to, and not replacing stuff you did want to, simply due to how complicated HTML syntax can be.

    The correct way to parse HTML is using a purpose-built HTML DOM parser.

    Annoyingly CF doesn’t have one built in, though if your HTML is XHTML, then you can use XmlParse and XmlSearch to allow you to do an xpath search for only text (not tags) that match your text… something like //*[contains(text(), 'span')] should do (more details here).

    If you’ve not got XHTML then you’ll need to look at using a HTML DOM parser for Java – Google turns up plenty, (I’ve not tried any yet so can’t give any specific recommendations).

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

Sidebar

Related Questions

I have a txt variable that contains my html string that I need to
I have a string as a HTML source and I want to check whether
I have a string of HTML that I use as jQuery input document. //
I have a string that has HTML & PHP in it, when I pull
I have a variable ( $output ) that is set to a string. To
I have a variable ( $output ) that is set to a string. To
I have a txt file which actually is a html source of some webpage.
I have a function that gets the title from a HTML source (I curl
I have an external HTML source that I want to scrape and either transform
i have HTML page source of website saved as String in string PageSource; i

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.