Cold Fusion String Stripping

March 23, 2009

Development

I’m tired of google-ing for a good string stripping reference, so I’ve found what I believe to be the most efficient way accomplishing this task (ala ) 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") />  
, , ,

No comments yet.

Leave a Reply