I want to get the first match of a regex.
In this case, I got a list:
text = \'aa33bbb44\' re.findall(\'\\d+\',text)
Maybe this would perform a bit better in case greater amount of input data does not contain your wanted piece because except has greater cost.
def return_first_match(text): result = re.findall('\d+',text) result = result[0] if result else "" return result