Link to home
Start Free TrialLog in
Avatar of ehart12
ehart12Flag for United States of America

asked on

Rereplace, remove all special characters except space

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

ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
\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
Ah! A guru without spectacles <|;-)
Avatar of ehart12

ASKER

azadisaryev,  

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

Thank you very much,

Eric
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.