I am having this below regex pattern. I want to allow these below characters as special characters.
- {
- }
- [
- ]
Regex regEx = new Regex(@"^(?=.*[A-Z])(?=.*[!@#$%^&*()+_<>~-])(?=.*[0-9])(?=.*[a-z]).{8,15}$");
Is there a way to add them
I am having this below regex pattern. I want to allow these below characters as special characters.
Regex regEx = new Regex(@"^(?=.*[A-Z])(?=.*[!@#$%^&*()+_<>~-])(?=.*[0-9])(?=.*[a-z]).{8,15}$");
Is there a way to add them
You'll need to escape them within the regex. Within a regular expression, you can refer to "\["
to get a '['
character, for example.
Note that in C, C#, C++, Java, etc, you usually need to double up the '\'
character to escape the escape character. So when adding '['
to your regex, you would actually use "\\["
. In your case you're using an @""
so you've escaped that trap.