Pete Freitag Pete Freitag

REFind and ReReplace support \r \n and \t

Published on March 28, 2005
By Pete Freitag
coldfusion

I noticed today that the regular expression functions in CF support the newline character \n Chr(10), carriage return \r Chr(13), and tab \t Chr(9).

Note that you can use these special character matchers inside the find pattern of ReReplace but you cannot use them in the replace expression of ReReplace.

This is probably new as of CFMX 6.0 when they moved to a Java implementation. But perhaps this has always been there, and I just never noticed it?

Here's a code example:

<cfsavecontent variable="data">
here is my 
break
</cfsavecontent>

<cfoutput>#ReReplace(data, "\n", "<br />", "ALL")#</cfoutput>

It is much easier to use \n than going to an ASCII table and looking up the character code. I always get the codes for \r and \n mixed up, so I end up looking them up every time I want to use them.



cfml regex

REFind and ReReplace support \r \n and \t was first published on March 28, 2005.

If you like reading about cfml, or regex 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


Comments

FWIW it wasn't there in CF5; thanks for the heads up as we're in the middle of 5->7 migration, having skipped 6 altogether.
by Pete Jordan on 03/29/2005 at 5:47:38 AM UTC
Oh baby, baby.
by Phillip Senn on 12/03/2005 at 10:23:37 PM UTC