notepad++password-policy

(Notepad++)Remove lines which doesn't meet password policy


The Password Policy:

Each password should have at least 3 of these:

  1. Contain Numbers
  2. Contain a-z
  3. Contain A-Z
  4. Contain special characters !@#$%^&*()_+

For example, this list:

12345678
adfghj
AASDFGHJ
!@#$%^&
1234as
1234ASDF
1345!#$%
asdfg!@#$
ASDFGB!#$$
SSRasd
Goodone123
G00done!@#
1@a
Aa1

Should be like this:

Goodone123
G00done!@#
1@a
Aa1

Thanks for helping :)


Solution

  • Let's see what regex can match your passwords:

    ^                                             # Start of line
     (?:                                          # Start of the alternation group
       (?=.*\d)(?=.*[a-z])(?=.*[A-Z])             # Conditions 1, 2, 3
       |
       (?=.*\d)(?=.*[a-z])(?=.*[!@#$%^&*()_+])    # Conditions 1, 2, 4
       |
       (?=.*\d)(?=.*[A-Z])(?=.*[!@#$%^&*()_+])    # Conditions 1, 3, 4
       | 
       (?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+]) # Conditions 2, 3, 4
       | 
       (?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+]) # Conditions 1, 3, 4
     )
     .*                                           # The line itself is matched
    $                                             # Up to the end of line
    

    See the regex demo

    To invert it, we just need to convert the non-capturing alternation group above to a negative lookahead by a mere replacing the : with !:

    ^                          # Start of line
     (?!                       # A negative lookahead
    

    See the online demo

    To use this in Notepad++, check Match case option, and add \R* at the end of the pattern to also remove linebreaks after the removed lines. A one-line for use in NPP:

    ^(?!(?=.*\d)(?=.*[a-z])(?=.*[A-Z])|(?=.*\d)(?=.*[a-z])(?=.*[!@#$%^&*()_+])|(?=.*\d)(?=.*[A-Z])(?=.*[!@#$%^&*()_+])|(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+])|(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+])).*$\R*
    

    enter image description here