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) 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(......) # findall() returns all match (list of string) # finditer() returns a list (or iterator) of the match object