Argh il Beri piu` veloce che mai :D
2012/7/20 Marco Beri <marcob...@gmail.com>: > 2012/7/20 Walter Valenti <waltervale...@yahoo.it> >> >> Ho una stringa che per essere verificata deve "matchare" due o più pattern >> diversi. >> La proma cosa che i viene in mente è avere diverse reg. expr. e fare la >> verifica con degli AND. >> Es: >> p1=re.compile(pattern1) >> p2=re.compile(pattern2) >> if p1.match(stringa) and p2.match(stringa): >> ##fai quello che devi. >> Mi chiedevo: c'è la possibilità di usare usa sola reg. expr. che sia un >> "and" tra i vari pattern ? > > > L'and non esiste, come esercizio di (non)stile si potrebbe usare il > lookaround: >>>> import re >>>> re.match("(?=.*a)(?=.*b)", "xxxxxxxx") >>>> re.match("(?=.*a)(?=.*b)", "xxxaxxxx") >>>> re.match("(?=.*a)(?=.*b)", "xxxaxbxx") > <_sre.SRE_Match object at 0xb6ebcf00> >>>> re.match("(?=.*a)(?=.*b)", "xxxbxxax") > <_sre.SRE_Match object at 0xb72dd218> > > Ma io mi terrei l'and come hai fatto tu (tra l'altro puoi anche > cortocircuitare l'espressione per cui se non trovi la prima non cerchi > nemmeno la seconda). > > Ciao. > Marco. > > -- > http://beri.it/ - Un blog > http://beri.it/i-miei-libri/ - Qualche libro > > > > _______________________________________________ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python > -- Andrea _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python