Example:
import re
rx = re.compile("{0-9}")
Var1 =bla bla bla 54467
Var2= rx.findall(Var1)
number = ''.join(Var2)
My question is how to convert the number variable to int, i try to do so with int() but i get an error.
Or is there a way to create such a variable as int with another method?
Don’t use regular expressions for this.
filter()is uch easier and quicker:The above code will merge all numbers in the string into a single string. If you don’t want this, use
The same recipes adapted for Python 3.x are: