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.


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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.