вы находитесь на правильном шаге с предвзятыми утверждениями.
Ваши требования могут быть разбиты на:
- (? =. {8,})
- (? =. * \ Г)
- (? =. * [А-г])
- (? =. * [A-Z])
- (= * [@ # $% -]?.)
- [\ да-Za-Z @ # $% -] *
Собрав все это, вы получите:
foundMatch = Regex.IsMatch(subjectString, @"^(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%-])[\da-zA-Z!@#$%-]*$");
Что, в свою очередь, можно объяснить этим:
"
^ # Assert position at the beginning of the string
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
. # Match any single character that is not a line break character
{8,} # Between 8 and unlimited times, as many times as possible, giving back as needed (greedy)
)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
. # Match any single character that is not a line break character
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\d # Match a single digit 0..9
)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
. # Match any single character that is not a line break character
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
[a-z] # Match a single character in the range between “a” and “z”
)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
. # Match any single character that is not a line break character
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
[A-Z] # Match a single character in the range between “A” and “Z”
)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
. # Match any single character that is not a line break character
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
[!@#$%-] # Match a single character present in the list below
# One of the characters “!@#$”
# The character “%”
# The character “-”
)
[\da-zA-Z!@#$%-] # Match a single character present in the list below
# A single digit 0..9
# A character in the range between “a” and “z”
# A character in the range between “A” and “Z”
# One of the characters “!@#$”
# The character “%”
# The character “-”
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
$ # Assert position at the end of the string (or before the line break at the end of the string, if any)
"