> I'm trying to use REFind to get all of the anchor/href tags but I'm 
> coming up short.

RegEx is not necessarily the ideal tool for this - try a DOM Parser.


If you've got consistent/controlled input you can use regex, and here's a Java 
one that will work in most situations:

<a[^>]+?\shref\s*+=\s*+["']([^"']++)["'][^>]++>(.*?)</a>


To use that with CFML, you can use my jre-utils CFC (which is GPL Free 
Software, rather than a $15 per server tag).

Here's an example, along with a commented version of the above regex:

<cfset jre = createObject('component','jre-utils').init()/>

<cfsavecontent variable="reFindHyperlinks">(?xis)
                          # Flags (above):
                          # x = enable regex comment-mode;
                          # i = make case-insensitive;
                          # s = allow . to match newlines;
                          # Main Regex:
        <a[^>]+?          # start of tag, lazily match at least one non->
        \bhref\s*+=\s*+   # match href attribute, word boundary at start, allow 
whitespace around =
        ["']([^"']++)["'] # match value of href, possessive capture contents 
between the quotes (note: doesn't support inverted embedded quotes)
        [^>]++>           # rest of tag, possessively matching non-> then >
        (.*?)             # lazily capture any tag contents 
        </a>              # end of tag
</cfsavecontent>

<cfset Results = jre.matchGroups( reFindHyperlinks , cfhttp.FileContent ) />
<cfdump var=#Results# />

That will set Results to an array of matches, each one containing a struct with 
the matched string, plus an array of the groups.


All make sense? 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:322985
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to