Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 29, 2012 13:34
ColdFusion 10 - reEscape() vs. Java Pattern's Quote() Method
<cfscript>
// Escape a string with ColdFusion 10's new reEscape() method.
// This escapes all the special control characters in the string.
//
// NOTE: This escape sequence can be used in BOTH a ColdFusion
// and a Java regular expression pattern.
writeOutput(
"reEscape: " &
reEscape(
"[who's] Johnny, she said (and smiled in her special way)."
)
);
writeOutput( "<br />" );
// Escape a string using Java Pattern's quote() function. This
// escapes all the special control characters in the string.
//
// NOTE: This escape sequence can ONLY BE USED in a Java regular
// expression pattern.
writeOutput(
"Quote: " &
createObject( "java", "java.util.regex.Pattern" ).quote(
"[who's] Johnny, she said (and smiled in her special way)."
)
);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment