loading...

Use Java replaceAll() instead of ColdFusion ReReplaceNoCase()

gamesover profile image James Moberg ・1 min read

This blog post is in response to this blog post "Regular expressions – practical examples to get you started". (My comment wasn't accepted after submitting twice and I'd rather post it somewhere that I have a little control as Adobe's community content tends to get deleted over time.)

We've encountered some unpreventable ColdFusion hard errors (that can't be prevented using try/catch) when using ReReplaceNoCase() in our application framework. Here are some reported bugs that are similar:
https://tracker.adobe.com/#/view/CF-3928688
https://tracker.adobe.com/#/view/CF-4165797

To work around this intermittently occuring bug (which Adobe classifies as "UserError" or "AsDesigned"), we started casting the initial value as a string (required for Java; not all CF-typeless variables contain pure "string" values) and using Java's replaceAll(). Our functions now seem faster, but more importantly there's no occasional CFError occurring in any of our apps.

When using regular expressions with ColdFusion, the ReEscape() function (available since CF10, but not available in Lucee at the time of this article) simplifies escaping characters that match regular expression control characters.

If interested in using more regex matching functions in ColdFusion, check out Ben Nadel's JRegEx:
https://www.bennadel.com/blog/3322-jregex—a-coldfusion-wrapper-around-java-s-regular-expression-patterns.htm

Posted on by:

gamesover profile

James Moberg

@gamesover

I’m a ColdFusion web application developer at SunStar Media located in Monterey, CA. I am a fan of technology, music and web development.

Discussion

markdown guide