Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Rereplace, remove all special characters except space

Posted on 2009-05-20
5
Medium Priority
?
5,222 Views
Last Modified: 2012-05-07
I have descriptions of items that I need to remove ALL characters that are not letters or numbers, and I would like to preserve spaces.  I am new to expressions and on overload since I cannot seem to come up with the magical solution...

REReplace(str, "[^0-9a-zA-Z_]", "", "ALL")

Any suggestions?

Thank you,

Eric

0
Comment
Question by:ehart12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 200 total points
ID: 24435115
For real RegExp gurus is this one:

REReplace(str, "[^\w\s]", "", "ALL")

For all others is this one:

REReplace(str, "[^0-9a-zA-Z _]", "", "ALL")

0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24437902
\s will also leave tabs, carriage returns, line and form feeds in the string, if any...
and it looks like _ is not one of the allowed characters, according to the question...

one of these should do the trick:

REReplace(str, "[^\w ]", "", "all")
REReplace(str, "[^0-9a-zA-Z ]", "", "all")
REReplace(str, "[^[:alnum:] ]", "", "ALL")

Azadi
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24438904
Ah! A guru without spectacles <|;-)
0
 

Author Comment

by:ehart12
ID: 24447867
azadisaryev,  

I tried dozens of different combinatioins and "REReplace(str, "[^\w ]", "", "all")" did the trick!

Thank you very much,

Eric
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24448616
That line was not from me, you see?
My proposal was adding meta char \s which includes also \n and \t to the space character as Azadi stated.
I proposed \s for better readability because tab and new line character do normaly not mess with space in line input fields but do so in textarea fields.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question