J'ai un morceau de texte et je dois analyser les noms d'utilisateur et les hachages. En ce moment je le fais avec deux expressions régulières. Pourrais-je le faire avec une seule expression régulière multiligne?python: expression régulière multiligne
#!/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)
ou même: 're.findall (r » (? s) Bonjour, (? P [^.] +) \ .. +? Hash: (? P [^.] +) ', Test_str) '(c'est-à-dire, inclure le drapeau dans le motif) –
tzot