I would like to extract all the numbers contained in a string. I can't use regex, is there any other way?
Example:
minput = "BLP45PP32AMPY"
Result:
4532
I would like to extract all the numbers contained in a string. I can't use regex, is there any other way?
Example:
minput = "BLP45PP32AMPY"
Result:
4532
You can use str.isnumeric
:
minput = "BLP45PP32AMPY"
number = int("".join(ch for ch in minput if ch.isnumeric()))
print(number)
Prints:
4532
final_integer = int("".join([ i for i in minput if i.isdigit()]))