Solved

Rereplace, remove all special characters except space

Posted on 2009-05-20
5
4,776 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …

790 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