I've seen many posts on this but I still can't get it to work, I have no idea why.
What I have is a relatively simple strings with some floating point and integer numbers in it, e.g.: '2 1.000000000000000 1 1 0'. I want to extract only the integers from it, in this example only 2, 1, 1, 0 (not the 1 that's followed by 0s).
I know I have to use lookbehind and lookahead to rule out numbers that are preceded or followed by a .. I can successfully find the numbers that are preceded by a coma, in the said case the 0:
import re
IntegerPattern = re.compile('-?(?<=\.)\d+(?!\.)')
a = '2 1.000000000000000 1 1 0'
IntegerPattern.findall(a)
will return ['000000000000000'], exactly as I want. But when I try to find numbers that are not preceded by .s this doesn't work:
import re
IntegerPattern = re.compile('-?(?<!\.)\d+(?!\.)')
a = '2 1.000000000000000 1 1 0'
IntegerPattern.findall(a)
returns ['2', '00000000000000', '1', '1', '0']. Any ideas why? I'm completely new to regular expressions in general and this just eludes me. It should work but it does not. Any help would be appreciated.