I want to define a ‘valid’ input, which is _-. won’t be allowed in the end or in the begining of the string, only allowed in the middle.
Acceptable characters (location doesn’t matter): a-zA-Z0-9 and all the hebrew letters which I don’t know how to allow them in a regex (maybe just hard-coding all the letters?)
Unacceptable characters (location doesn’t matter): All symbols, except the special ones I provided before.
I don’t know how to build this pattern, and if you can add tips and comments on every section so I will understand. Thanks!
This is not for homework, just for self learning.
If you want to allow “_.-” without duplicates:
If you want to allow white spaces in the middle:
If you want white spaces + “_.-” without duplicates:
So using the Regex:
Also, if you plan on using the regex many times in the code, I suggest adding RegexOptions.Compiled flag, to increase speed.