Potrzebowałem wyszukać nazwy użytkowników, które są do siebie podobne, i co powiedział Ned Batchelder bardzo pomocny. Uważam jednak, miałem czystsze wyjście kiedy użyłem re.compile tworzyć kryteria wyszukiwania ponownego wyrażenia:
pattern = re.compile(r"("+username+".*):(.*?):(.*?):(.*?):(.*)"
matches = re.findall(pattern, lines)
wyjściowe mogą być drukowane przy użyciu następujących:
print(matches[1]) # prints one whole matching line (in this case, the first line)
print(matches[1][3]) # prints the fourth character group (established with the parentheses in the regex statement) of the first line.
użyć ciąg konkatenacji –