import re # create a regular expression object for UVA computing ID computingID = re.compile(r"[a-z]{2,3}[0-9][a-z]{1,3}") text = '''this is a bunch of things ab3e ab12e abc1e abc12e ab12de ab1de abcde 123445''' # search() returns the first matched object search_result = computingID.search(text) # return an object print(search_result) # start() returns the first index of the match print(search_result.start()) # end() returns the last index of the match print(search_result.end()) # group() returns the matched object print(search_result.group()) # findall() returns all match (list of string) findall_result = computingID.findall(text) print(findall_result) for thing in findall_result: print(thing) # finditer() returns a list (or iterator) of the match object finditer_result = computingID.finditer(text) print(finditer_result) for thing in finditer_result: print(thing, thing.start(), thing.end(), thing.group())