This is a very basic question ..sorry....I'm a newbie. A few specifications: -The string is an arithmetic expression. -It would love the output to return the number i.e a 2 digit number or 3 digit number depending on the string. For example if string is "12+3-5/6" Then the output should be 12. I have tried this:
import re
s = "12*9-6/4"
m = re.search("\d" , s)
if m:
print(s[m.start()])
else:
print("try again")
But this outputs the first number it sees and not the whole 2 digit number. How do I change it?
input = '123abc456def'
output = re.findall(r'^\d+', input)
But this returns the value in square brackets. Ht do I just get a number.