ColdFusion RegEx White List Example

Posted by Quinn Madson | Posted in | Posted on 9:49 AM

0

I needed to build a function that would strip out characters in event information because, otherwise it would break a JSON feed. Here is what I used:


<cffunction name="jsonSafe" access="private">
<cfargument name="str" type="string" required="true">
<cfset newStr = reReplace(arguments.str, '[^[:alnum:][:space:]$=;.?!\\/&"''`():,\[\]{}_\-]', '_','all')>
<cfreturn newStr>
</cffunction>

Comments (0)