Scanning two integers separated by an unknown character
2 answers
I would use re.split()
for this:
In [9]: re.split(r'\D', '1024x768')
Out[9]: ['1024', '768']
or, if you also need to capture the separator character:
In [11]: re.split(r'(\D)', '1024x768')
Out[11]: ['1024', 'x', '768']
(In both cases, apply int()
to strings to convert them to integers.)
+4
source to share