Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to remove some special chars

I'm looking for a regular expression that can remove all the following characters from a string (and Whitespace too):

~ % & \ ; : " ' , < > ? #

Can you help me? I'm coding in ActionScript 3.

like image 636
Lotts Avatar asked May 13 '11 10:05

Lotts


People also ask

How do you restrict special characters in regex?

var nospecial=/^[^* | \ " : < > [ ] { } ` \ ( ) '' ; @ & $]+$/; if(address. match(nospecial)){ alert('Special characters like * | \ " : < > [ ] { } ` \ ( ) \'\' ; @ & $ are not allowed'); return false; but it is not working.

How do I remove special characters from text in R?

Answer : Use [^[:alnum:]] to remove ~! @#$%^&*(){}_+:"<>?,./;'[]-= and use [^a-zA-Z0-9] to remove also â í ü Â á ą ę ś ć in regex or regexpr functions.


2 Answers

In ActionScript it goes like

yourString.replace(/[~%&\\;:"',<>?#\s]/g,"");

Same in Perl:

$_ = "~ % & \\ ; : \" ' , < > ? #";
s/[~%&\\;:"',<>?#\s]//g;
print; #prints nothing
like image 174
Thomas Hupkens Avatar answered Nov 15 '22 06:11

Thomas Hupkens


[~%&\\;:"',<>?#\s]+
like image 24
YOU Avatar answered Nov 15 '22 07:11

YOU