Hello I have created a Regex to remove invalid characters in a string:

Here it is:

Regex replace_invalid_caracters = new Regex(@"[\\|/|*|+|-|%|=|^|@|#|$|!|~|`|?|<|>|:|(|)|{|}|;|,|_|]");

The thing is that then I use it in a method to remove this invalid characters.

It manages to remove all invalid characters except for "-". I would like to know how to tell the regex expression to remove "[" or "]" and also "|" and of course "-".

What can I do?

Thanks in advance.

Ok,

I found the solution, I just had to add the "\" before the symbol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.