Add Comment
Get href labels using RegEx Tutorial
ColdFusion Tutorial #24
Ever wondered how you could use regex to find all the link labels in a string. Not the links - but the label for the link. It is relatively easy to grab all the matches for a regex in ColdFusion 8, consider the following code block:
demo.cfm
I create a string with a few links in it on lines 1-7.I then use the new reMatch function to grab all the matches. My regex says - find all HTML links. It isn't exactly perfect, it won't match a closing A tag that has an extra space in it, but you get the picture. This results in a match of all the links this is done on line 9.
But you will notice that the HTML links are still there. How can we get rid of them? I simply looped over the array and did a second pass on lines 12-15.
Run the demo to see the dump output.
Demo
See this code running!
Download
Download this code as a zip!
Comments
There are no comments!Click button to add a comment
Author
Raymond Camden
Published
Friday 30 Nov 2007Original
This tutorial has been modified and published with permission of the author. The original tutorial can be found herehttp://www.coldfusionjedi.com/index.cfm/2007/11/7/Ask-a-Jedi-Getting-all-the-link-labels-from-a-string-in-ColdFusion