I'm trying to improve some code in order to get a better perfomance, I have to do a lot of pattern matching for little tags on medium large strings, for example:
import re STR = "0001x10x11716506872xdc23654&xd01371600031832xx10xID=000110011001010\n" def getID(string): result = re.search('.*ID=(\d+)', string) if result: print result.group(1) else: print "No Results"
Taking in mind the perfomance I rewrite it:
def getID2(string): result = string.find('ID=') if result: result += 3 print string[result:result+15] else: print 'No Results'
Are there a better way to improve these approaches? Any comments are welcome...