Allow specific characters in the middle, but not at the end or beginning

I want to define a "valid" input that will _-.not be allowed at the end or at the beginning of the line, only in the middle is allowed.

Valid characters (location doesn't matter): a-zA-Z0-9and all the letters in Hebrew that I don’t know how to resolve them in regular expression (maybe just hard-coded all the letters?)

Unacceptable characters (location does not matter): all characters except the special ones that I introduced earlier.

I do not know how to create this template, and if you can add tips and comments to each section, I will understand. Thank!

This is not for homework, just for self-study.

+1
source share
1
@"^[a-zA-Z\dא-ת][a-zA-Z_\-\.\dא-ת]*[a-zA-Z\dא-ת]$"

"_.-" :

@"^[a-zA-Z\dא-ת]([a-zA-Z\dא-ת]+[_\.\-]?)*[a-zA-Z\dא-ת]$"

:

@"^[a-zA-Z\dא-ת][a-zA-Z_\-\.\d\sא-ת]*[a-zA-Z\dא-ת]$"

+ "_.-" :

@"^[a-zA-Z\dא-ת]([a-zA-Z\d\sא-ת]+[_\.\-]?)*[a-zA-Z\dא-ת]$"

, Regex:

var isValid = Regex.IsMatch(input, @"...");

, , RegexOptions.Compiled, .

var isValid = Regex.IsMatch(input, @"...", RegexOptions.Compiled);
+1

All Articles