Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stripping specific characters 1

Status
Not open for further replies.

Extension

Programmer
Joined
Nov 3, 2004
Messages
311
Location
CA
Hi,

I searched for some threads on the subject but I didn't find anything close.

I'm looking for a simple regEx to only keep alphanumeric chracters and dashes and strip the rest.

Code:
<cfset str = "+{343} 343-34443 34 (@3222)" >
<cfset str_safe = ReReplaceNoCase(str,"[^a-z0-9]+","","ALL") >

In the example above the "str" should end up like this: 343343-34443343222

The Regex I'm using will only keep the Alphanumeric characters and not the dashes.

Thanks.
 
Just a simple change needed:

Code:
<cfset str = "+{343} 343-34443 34 (@3222)" >
<cfset str_safe = ReReplaceNoCase(str,"[^a-z0-9\-]+","","ALL") >

If you notice, all I added was \-, with the slash escaping the dash so that Coldfusion knows to allow that as part of the string rather than a regex operator.

Hope this helps

Wullie

YetiHost - Quality Coldfusion 7/Windows Hosting

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 

Thank you very much for your help Wullie.
The clear explanation was also appreciated.





 
Wullie

I have another question for you.
If I want to escape more than one character, should I do it this way ?

Code:
<cfset str_safe = ReReplaceNoCase(str,"[^a-z0-9\-\@\#]+","","ALL") >
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top