The ([a-zA-Z]*)
regular subexpression does not accept digits, you might have meant ([a-zA-Z0-9]+)
or another choice would be (\S+)
.
You have already used \s
, are you aware of \S
? Because you are using \s
as the "delimiter" of your password token, you might as well be consistent and define the password as consisting of any characters which are not delimiters.
You could also simplify your regular expression overall as follows:
^(?:.*:password(\sis|:)\s(\S+)\s.*)*$
As pointed out by codaddict's analogy to PHP's preg_match_all
, you also need to call re.findall. To do so, you will need to change the regular expression to one which is not overlapping, such as:
password(\sis|:)\s(\S+)
and then you will receive in the return value from re.findall() a list of matches, each consisting of a list of groups matched.