getting only the first Number from String in Python

Just use re.search which stops matching once it finds a match.

re.search(r'\d+', headline).group()

or

You must remove the forward slashes present in your regex.

re.findall(r'^\D*(\d+)', headline)

Leave a Comment