Auto-Linking Comments

by Pete Freitag

To avoid comment spam, my blog comments are displayed as plain text. However urls to other entries on my blog are often posted to in the comments. So I wrote a simple regular expression to create hyperlinks out of them:

REReplaceNoCase(comments.comment, 
	"(http://www\.petefreitag\.com/[^[:space:]]+)",
	"<a href=""\1"">\1</a>", 
	"ALL")

If you want this to work with or without the www you can use something like this for the regular expression:

(http://w*\.?petefreitag\.com/[^[:space:]]+)

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.