Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
password regex with optional special characters
  • ^ - 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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment