How do I write a regular expression that includes all keyboard characters except '~' and ','?
views:
1174answers:
4
+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
2009-05-07 10:56:02
However this will allow some special charcaters that are not in keyboad that might come acccidentally by doing copy nad paste from some text.
2009-05-07 10:58:38
A:
Daniel Brückner
2009-05-07 11:04:51
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
2009-05-07 13:45:06