That may be what I did, can't remember. But... that method worked and was 16
times faster ;-)

-----Original Message-----
From: chopper [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 18, 2007 12:12 PM
To: CF-Talk
Subject: Re: Regular Expression to count links

True about the runaway loop--- it was late ;-)

Here's the corrected code:

<cffunction name="GetLinkCount">
  <cfargument name="s" type="string">
  <cfset var count = 0>
  <cfset var foundPos = 1>
  <cfset var nextPos = 1>
  <cfloop condition="foundPos">
    <cfset foundPos = REFindNoCase("<a\s+[^>]*?href[^>]+>.*?</a>", s,
nextPos)>
    <cfif foundPos>
      <cfset nextPos = foundPos + 1>
      <cfset count = count + 1>
    </cfif>
  </cfloop>
  <cfreturn count>
</cffunction>

Regarding efficiency, I think you must have compared my code to your
version that simply uses FindNoCase instead of REFindNoCase.
Comparing the two versions with RegExps, my code is nearly 4 times
faster.  This would have to be the case because searching, copying,
and replacing in strings are not simple operations, and it's best to
minimize them, as above.  Also, RegExps are much less efficient than a
plain old Find, but correspondingly more powerful, so it's more
efficient to use Find instead of REFind if you don't mind counting
named anchors as links.


On 5/18/07, Bobby Hartsfield <[EMAIL PROTECTED]> wrote:
> That's also a runaway loop when there are no links found ;-)
>
> -----Original Message-----
> From: Bobby Hartsfield [mailto:[EMAIL PROTECTED]
> Sent: Thursday, May 17, 2007 11:53 PM
> To: CF-Talk
> Subject: RE: Regular Expression to count links
>
> Actually... the while loop I posted is considerably faster. About 16ms
> faster. Maybe it's the loop or the cfscript... I dunno.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Macromedia ColdFusion MX7
Upgrade to MX7 & experience time-saving features, more productivity.
http://www.adobe.com/products/coldfusion?sdid=RVJW

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:278637
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to