asp.net - VB.NET Regex Boolean Match -


i score password based on various features, don't believe regex correct:

    if regex.ismatch(password, "/\d+/", regexoptions.ecmascript)         'contains number         score += 1     end if      if regex.ismatch(password, "/[a-z]/", regexoptions.ecmascript)         'contains lowercase letter         score += 1     end if      if regex.ismatch(password, "/[a-z]/", regexoptions.ecmascript)         'contains uppercase letter         score += 1     end if      if regex.ismatch(password, "/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/", regexoptions.ecmascript)         'contains special character         score += 2     end if 

how fix this? believe these formatted c# not vb.net.

the .net regex class takes raw text of regular expression.

you should not wrap in / characters; match literal text /.

some other notes:

  • you don't need regexoptions.ecmascript
  • character classes not comma-separated
  • you're missing large number of special characters. use negated class (all non-alphanumeric chars)
  • you can make them faster pre-compiling them reusable regex instances instead of re-parsing each regex every time.

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -