tags:

views:

1174

answers:

4

How do I write a regular expression that includes all keyboard characters except '~' and ','?

+2  A: 

umm, like this?

[^~,]

Now to exclude characters not in keyboard, I believe you gotta include them all,

[a-zA-z0-9\t\n ./<>?;:"'`!@#$%^&*()[]{}_+=-|\\]

which pretty much covers it but looks like a crazy way to get things done. Maybe the problem definition can help you add more stuffs to exclude in the first list [^~,] than try to create a huge list of all keyboard chars

Sujoy
However this will allow some special charcaters that are not in keyboad that might come acccidentally by doing copy nad paste from some text.
A: 

Different keyboards have different characters on them.

Matthew Wilson
I want from normal US english keyboad
A: 
Daniel Brückner
A: 

You didn't say what language/tool you're using, but in Java I would go with this regex:

"[\\p{Print}&&[^~,]]"

That's the intersection of two sets: all printing ASCII characters, and all characters that aren't a tilde or a comma.

Alan Moore