manoj, resurrecting this question because there's one tidy solution that wasn't mentioned. This problem is a classic case of the technique explained in this question to "regex-match a pattern, excluding..."
We can solve it with a beautifully-simple regex:
'[^']*'|([^\w'\s]+)
The left side of the alternation |
matches complete quoted strings
. We will ignore these matches. The right side matches and captures special characters to Group 1, and we know they are the right ones because they were not matched by the expression on the left.
All that's left to do is to replace the match with an empty string, but only when Group 1 is set. The way do to this is different in every language, but it's not complex. The question and article below fully explain the technique (the article has code samples).
On this demo, if you look in the right pane, you can see how Group 1 only captures the chars you want to replace.
Reference