I seen Q&A like this and this but I still have a problem.
What I want is to get a string that might contain non-digits characters, and I want to only extract 2 numbers from that string. So, if my string is 12 ds d21a
I want to extract ['12', '21']
.
I tried using:
import re
non_decimal = re.compile(r'[^\d.]+')
non_decimal.sub("",input())
and fed this string 12 123124kjsv dsaf31rn
. The result was 12123124
which is nice, but I want the non-digit characters to separate the numbers.
Next I tried to add split
- non_decimal.sub("",input().split())
. Didn't help.
How can I do that (assuming there is way that does not include scanning the whole string, iterating over it and extracting the digits "manually")?
For more clarification, this is what I want to achieve, in C.