I want to be able to get the first two numbers in a string and print the first two numbers, I want to do this using regex, this is currently my code:
import re string = str(input("String: ")) product = re.findall('[a-z].*[a-z]', string) print(product)
I would like an output like this for example:
import re string = str(input("String: ")) //Air Max 90 or Air Max 987 //Logic regex here //Output Air max 90 Air Max 98
To clarify, what I need is to display the string with the first two numbers and exclude all the rest of the number that exists.
I want to be able to display the numbers that are in the string, but only the first two, how can I do this?
You may use this regex:
^.*? we make sure to stop match when we get a word starting with 2 digits that must be followed by another digit after optional spaces or else match till the end.