Pete Freitag Pete Freitag

Auto-Linking Comments

Published on June 24, 2005
By Pete Freitag
coldfusion

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:]]+)


regex comments blog rereplace cfml

Auto-Linking Comments was first published on June 24, 2005.

If you like reading about regex, comments, blog, rereplace, or cfml then you might also like:

Fixinator

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.


Try Fixinator

CFBreak
The weekly newsletter for the CFML Community