How to use coldfusion to replace dynamic text when using cfhttp

I'm using cfhttp to pull in page content from another site and then using ReplaceList to format the output to the style that I want. This works fine for most of the content except for the date content which is generated dynamicly and I don't want to display the date content. I have not been able to strip out the date content because the format is sometimes 4 characters (12:30) sometimes 3 characters (1:30) and sometimes 1 character (3). Since the date code is always between the same specific tags (<SPAN CLASS='byttl'><br>AP Top News At 1:16 p.m. EDT</SPAN>) I'm wondering if there is some way to replace everything that is placed between these tags with nothing, or with another string? Sort of like a wildcard.

Here is an example of the code I'm running now:

<cfhttp method="get" url="" resolveurl="yes">

<cfset output = #ReplaceList(cfhttp.FileContent,"<table BORDER=0>,<TR>,<TD>,</SPAN>,</TR>,</TD>,<SPAN CLASS='byttl'>,<SPAN CLASS='storylink'>,<SPAN CLASS='topheadline'>,<SPAN CLASS='firsttopheadline'>,<br>AP Top News At,EDT,....,</TABLE>,..." , ",,,,,,,,,,,,,,,,<br>")#>

<font size="-1" face="Arial, Helvetica, sans-serif">#output#</font>
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Replace the strings <SPAN CLASS='byttl'><br>  and </SPAN> with single characters that you know will not appear anywhere else in the string.

Then do a rereplace of anything between those characters with the date that you want. Then put the <SPAN CLASS='byttl'><br>  and </SPAN>, back.

You will need to use a regular expression to do the replace BETWEEN part.

I replaced all instances of #<CF variable># with the string "dynamically generated" like this -
<CFSET b= #REReplace (TRIM(string), "{1}\~.*{1}\~","&laquo;dynamically generated&raquo;", "all") #>
where I had a variable in the string representing a number. I would then get
 something like this
There are «dynamically generated» Australians currently registered as living in Belgium.
basically what you want to do is to search for the start span tag:
<cfset startPosTag = findnocase(output,"<span class='byttl'>")>

get the first position after that tag:
<cfset startPosContent = startPosTag + 20>

get the first position of the end tag after that specific start span tag
<cfset endPosTag = findnocase(output,"</span>",startPosContent)>
get the content
<cfset content = mid(output,startPosContent,endPosTag - startPosContent)>

then just replace the content with whatever...
<cfset newOutput = replace(output,content,'whatever')>

something like that...
PS I left something out in the above example. This should make it clearer.

I have a string called summary. I replace all the pound signs (but it could be any string) with a tilda ~.

<cfset a= #Replace(summary, "##", "~" , "all") #>

Then I replace everything between two tilda's with the string 'dynamically generated'.
<CFSET b= #REReplace (TRIM(string), "{1}\~.*{1}\~","&laquo;dynamically generated&raquo;", "all") #>

b will now countain not #numaussies# but
are «dynamically generated»

as in
There are «dynamically generated» Australians currently registered as living in Belgium.

I did this for output of a Verity search query where the search string returned could have CF variables that were not defined in the page displaying the search results.

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

McHackAuthor Commented:
So far no luck,

Basically what I'm trying to do is strip out everything except for the links and the text. I've been successful with everything except for the date portion. Ideally I would just like to get ride of the date but have not been able to. I have not been able to remove the comments either since they are dynamic too but so far they don't seem to interfere with anything.  

Here is an example of what the code looks like when I first bring it in before removing anything:

<!-- BEGIN PACKAGE 150058 -->
<!-- $Id:,v 1.57 2003/04/22 21:01:40 mike Exp $ -->
<!-- $Id:,v 1.10 2003/04/22 21:01:41 mike Exp $ -->
<!-- BEGIN TOP HEADLINE 9009 2003/10/23 13:18:11 -->
<!-- $Id:,v 1.49 2003/04/22 21:01:41 mike Exp $ -->
<TR><TD><SPAN CLASS='byttl'><br>AP Top News At 1:16 p.m. EDT</SPAN></TD></TR>
<!-- $Id:,v 1.52 2003/04/22 21:01:41 mike Exp $ -->
<TR><TD><SPAN CLASS='storylink'><SPAN CLASS='topheadline'><SPAN CLASS='firsttopheadline'>&nbsp;<BR>
<A HREF=>U.S., U.N. Seek Billions to Rebuild Iraq</A></SPAN></SPAN></SPAN><BR>
MADRID, Spain (AP) -- U.S. and Iraqi officials pleaded for billions to rebuild Iraq at a donors conference that opened Thursday with warnings that they might not get all they need right away....</TD></TR>
<!-- END TOPHEADLINEITEM 7367213 -->
<!-- $Id:,v 1.52 2003/04/22 21:01:41 mike Exp $ -->
<TR><TD><SPAN CLASS='storylink'><SPAN CLASS='topheadline'>&nbsp;<BR>
<A HREF=>300 Illegal Workers Arrested at Wal-Marts</A></SPAN></SPAN><BR>
WASHINGTON (AP) -- Federal officials arrested more than 300 illegal workers at 61 Wal-Mart stores across the country early Thursday morning and searched the office of one of the retail chain's corporate executives, a federal official said....</TD></TR>
<!-- END TOPHEADLINEITEM 7367214 -->
<!-- $Id:,v 1.52 2003/04/22 21:01:41 mike Exp $ -->
<TR><TD><SPAN CLASS='storylink'><SPAN CLASS='topheadline'>&nbsp;<BR>
<A HREF=>Bush Heckled in Australian Parliament</A></SPAN></SPAN><BR>
CANBERRA, Australia (AP) -- Heckled inside and outside Australia's Parliament, President Bush offered a pointed answer to those who say the war with Iraq wasn't worth fighting....</TD></TR>
<!-- END TOPHEADLINEITEM 7367215 -->
<!-- END TOP HEADLINE 9009 -->
<!-- END PACKAGE 150058 -->

<cfset newText = reReplaceNoCase(cfhttp.filecontent, "<SPAN CLASS='byttl'><br>[^<]+</span>", "", "ALL")>

will remove the SPAN tags and all content between them, as long as there is always a "<br>" after the opening <span>.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
McHackAuthor Commented:
Thanks Chris, that's exactly what I needed. For future reference could you explain how the [^<] part works? Thanks again, here comes your points.
Hi McHack,

the regular expression means

everything that starts with "<SPAN CLASS='byttl'><br>", can be followed by anything except "<" and must end with "</span>".

[^<]+ means "one or more chars that are not '<'.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.