У меня есть фрагмент текста, и я должен разбирать имена пользователей и хэши. Сейчас я делаю это с двумя регулярными выражениями. Могу ли я сделать это только с одним многострочным регулярным выражением?python: многострочное регулярное выражение
#!/usr/bin/env python
import re
test_str = """
Hello, UserName.
Please read this looooooooooooooooong text. hash
Now, write down this hash: fdaf9399jef9qw0j.
Then keep reading this loooooooooong text.
Hello, UserName2.
Please read this looooooooooooooooong text. hash
Now, write down this hash: gtwnhton340gjr2g.
Then keep reading this loooooooooong text.
"""
logins = re.findall('Hello, (?P<login>.+).',test_str)
hashes = re.findall('hash: (?P<hash>.+).',test_str)
или даже: 're.findall (г» (? s) Здравствуйте, (? P [^.] +) \ .. +? Hash: (? P [^.] +) ', Test_str) '(то есть включить флаг внутри шаблона) –
tzot