c# - Allow underscore "_" as a special character -
this expression, not accepting "_" special character
{(?=.{8,})(?=(.*\d){0,})(?=(.*\w){1,})}
when set conditions inside pattern, not forget consume characters, add .+
capture 1 or more symbols, or .*
capture 0 or more characters:
{(?=.{8,})(?=(.*\d){0,})(?=(.*[^a-za-z0-9]){1,}).+}
however, if want require string have @ least 1 digit , @ least 1 non-word symbol (excluding underscore), i'd suggest using
{(?=.{8,})(?=(?:.*\d){0,})(?=(?:.*[^a-za-z0-9]){1,}).+}
see demo.