-1

Passwords should contain: uppercase and lowercase letters and (Digit OR Symbol)

So, how can I extract from lines having above rules from a password list?

Example:

123q
123
qwe
!@#123
123@
Qwe1
Admin
admin
Admin@
Admin#1

What I need:

Qwe1
Admin@
Admin#1
Mistalis
  • 17,793
  • 13
  • 73
  • 97
MinLo
  • 19
  • 2

1 Answers1

1

You can use a positive lookahead for each criteria for your password.

Here is a suggestion:

^(?=.*[A-Z].*)(?=.*[\d!@#$&*])(?=.*[a-z].*).*$
  • (?=.*[A-Z].*) at least 1 uppercase
  • (?=.*[\d!@#$&*]) at least one character of the list (a special character or a number)
  • (?=.*[a-z].*) at least 1 lowercase

Test it on regex101

Community
  • 1
  • 1
Mistalis
  • 17,793
  • 13
  • 73
  • 97
  • Could you help me and explain a bit how the regex is using the positive lookaheads? I'm trying to understand it based upon what I've read here: http://www.regular-expressions.info/lookaround.html but in the q(?=u) example I see it's the left 'character' and then followed by the lookahead, but I see no character to the left of your first lookahead. Your code clearly works but I'm having trouble seeing how. Thank you. – sniperd Jun 22 '17 at 13:45
  • @sniperd For example, in `(?=.*[A-Z].*)`: `.*` whatever characters before, then `[A-Z]` an uppercase, and then again `.*` whatever characters after. From [this answer](https://stackoverflow.com/a/2973609/4927984): `(?=REGEX_1)REGEX_2` matchs only if REGEX_1 matches; after matching REGEX_1, the match is discarded and searching for REGEX_2 starts at the same position. – Mistalis Jun 22 '17 at 14:13
  • would doing: ^(?=.*[A-Z])(?=.*[\d!@#$&*])(?=.*[a-z]).*$ also be OK in this specific case then? Only having the first .* in each 'set' I'm really trying to wrap my head around this :) – sniperd Jun 22 '17 at 14:17
  • @sniperd Nah, I don't think I will work. You need to say "I want an uppercase letter anywhere in the password". Without the ending `.*`, you do not say it may be anything after your uppercase. Get it? ;P – Mistalis Jun 22 '17 at 14:20
  • does the .* after all the look aheads take care of that though? Thank you for your responses. Every time I think have all the regex stuff figured out I find some puzzler! – sniperd Jun 22 '17 at 14:31