Простой pyparsing
версия:
from pyparsing import *
username = Word(alphas,alphanums+"_")
hash = Word(alphanums)
patt = ("Hello," + username("username") + '.' +
SkipTo("write down this hash:", include=True) +
hash("hash"))
for tokens,start,end in patt.scanString(test_str):
print tokens.hash, '->', tokens.username
# or to build a dict
hashNameLookup = dict((t.hash, t.username)
for t,s,e in patt.scanString(test_str))
Печать:
fdaf9399jef9qw0j -> UserName
gtwnhton340gjr2g -> UserName2