0

I am trying to remove all the non-word character in a string, but want to keep punctuation mark, is there a way I can form the regex to do it (in C# 4.0)?

I tried to Google but most of the information I get is about look forward or behind. I also try something like [\W(?^,)] but this is the look forward and if I do [(?=^,)] it will simply meet any characters in (?,=,^ and ,).

1 Answer 1

1

search for anything that is ^NOT [a word \w or a question mark ?]

[^\w?]

instead of NOT A WORD (\W) except question mark ?

Sign up to request clarification or add additional context in comments.

1 Comment

To be precise, [^...] is called a complemented character class, or negated character class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.