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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With