Solved

Rereplace, remove all special characters except space

Posted on 2009-05-20
5
4,571 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
  • 3
5 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 50 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now