Skip to content

March 23, 2009

Cold Fusion String Stripping

I’m tired of google-ing for a good Coldfusion string stripping reference, so I’ve found what I believe to be the most efficient way accomplishing this task (ala Regular Expressions) and am posting them here for my own reference. If these can help anyone else out in the process… great!


<!--- // Strip everything except numbers and letters // --->
<cfset variables.clean_string = rereplace(variables.dirty_string, "[^A-Za-z0-9]+", "", "all") />

<!--- // Strip everything but numbers // --->
<cfset variables.clean_string = rereplace(variables.dirty_string, "[^0-9]+", "", "all") />

<!--- // Strip everything but CAPITAL letters // --->
<cfset variables.clean_string = rereplace(variables.dirty_string, "[^A-Z]+", "", "all") />  

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments