JREReplace( strText, strRE, strNewText, strScope )

Downloadable Files

jrereplace_function.cfm.txt ( 3,721 Bytes )

This does the same thing as ColdFusion's REReplace() method. The difference here is that it uses a Java string under the hood and therefore can handle the much more powerful, complex Regular Expressions of Java's RegExp engine. Of particular importance is the positive look behind and negative look behind, which REReplace() cannot do.

With the use of the JREReplace(), there are some trade-offs and caveats. For starters, since we are using Java under the hood, we have to instantiate a Java string via CreateObject( "java", "java.lang.String" ) which comes with a performance hit.

Additionally, Java regular expressions use $N notation to refer to groups, not \N notation. So to refer to the 3rd grouping in a regular expression, you would use $3 in your replacement text.

Added April 21, 2006 / Updated April 21, 2006