Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can't think of a direct way to do this to be honest: regular expressions aren't very supportive of "must contain". What language are you writing this in? Personally, I'd do this by checking for each regular expression in turn and counting how many matches you get, so in python it would be something like this:</p> <pre><code>#!/usr/bin/python import re count = 0 mystring = "password" regexp = re.compile(r'[A-Z]') if regexp.search(mystring) is not None: count += 1 regexp = re.compile(r'[a-z]') if regexp.search(mystring) is not None: count += 1 # etc if count &lt; 3: print "Not enough character types" </code></pre> <p>You could also do this a bit more cleanly with:</p> <pre><code>#!/usr/bin/python import re regexpArray = [re.compile(r'[A-Z]'), re.compile(r'[a-z]'), re.compile(r'\d'), re.compile(r'[^A-Za-z0-9]')] count = 0 for regexp in regexpArray: if regexp.search(mystring) is not None: count += 1 if count &lt; 3: print "Not enough character types" </code></pre> <p>Alternatively, you could have a very complicated regular expression with lots of options (in different orders) or one of the various password strength checkers that you'll be able to find with google.</p> <p><b>Edit</b>:</p> <p>The python way to do this without regular expressions would be something like the following. I'm sure there's a .NET equivalent for this that would be much quicker than regular expression matching.</p> <pre><code>#!/usr/bin/python import string mystring = "password" count = 0 for CharacterSet in [string.ascii_lowercase, string.ascii_uppercase, "0123456789", r'''!"£$%^&amp;*()_+-=[]{};:'@#~,&lt;.&gt;/?\|''']: # The following line adds 1 to count if there are any instances of # any of the characters in CharacterSet present in mystring count += 1 in [c in mystring for c in CharacterSet] if count &lt; 3: print "Not enough character types" </code></pre> <p>There may be a better way of generating the list of symbols.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload