# 0708.py import re testo='fine 65 345 era 900 - 111' ris=re.search('(\d+) +(\d+).*?(\d+)',testo) if ris: for i in xrange(4): print ris.group(i) # 65 345 era 900 # 65 # 345 # 900 print ris.groups() # ('65', '345', '900') ####################################### testo='fine a65 345 era 900' ris=re.search('(yy)|a(\d+) +(\d+).*?(\d+)',testo) print ris.groups(default='--') # ('--', '65', '345', '900') ####################################### testo='era 56 83567 1560' ris=re.search(r'(\d+).*\1.*(\1)',testo) if ris: print ris.groups() # ('56', '56') ####################################### testo='era 56 83567 1560' ris=re.search(r'(\d+).*\g<1>.*(\g<1>)',testo) if ris: print ris.groups() # ('56', '56')