Solved

Rereplace, remove all special characters except space

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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