2011/10/6 roberto.prezi...@gmail.com <roberto.prezi...@gmail.com> > Ciao, > mi sono bloccato con una regular expression su python. > Sto cercando di mettere i due punti ad un mac address e togliere quello > finale, ma non riesco a far funzionare questa regexp che su sed va così > bene: > > *da terminale:* > > echo "00A1B2AABBCC" | sed 's/\(..\)/\1:/g;s/:$//' > > *con python :* > > >>> mac = "00A0BCAABBCC" > >>> mac.replace("\(..\)","\1:") > '00A0BCAABBCC' > >>> mac.replace("..","\1:") > '00A0BCAABBCC' > >>> mac.replace("..",":") > '00A0BCAABBCC' > >>> mac.replace("\.\.",":") > '00A0BCAABBCC' > > dove sbaglio ? >
A non usare le regex :-) >>> import re >>> ":".join(re.findall("..", mac)) 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