Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
password regex with optional special characters
^(?=.*\d)(?=.*[a-z])[\w~@#$%^&*+=`|{}:;!.?\"()\[\]-]{6,8}$
  • ^ - start of string
  • (?=.*\d) - require at least one digit
  • (?=.*[a-z]) - require at least a lowercase ASCII letter
  • (?=.*[A-Z]) - require at least 1 ASCII uppercase letter
  • [\w~@#$%^&*+=`|{}:;!.?\"()\[\]-]{6,8} - match (=consume) 6,8 characters only,symbols that are either alphanumeric, or _, or all those inside the character class
  • $ - end of string

For testing/demo go here: https://regex101.com/r/qN5dN0/5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.