I'm trying to separate lines into 3 sections using regex, with a typical line fitting into this kind of pattern:
-30.345 150.930 112.356
lat = float(re.match('[^\s]+', line).group(0))
long = float(re.match('.*?\s(\S+)\s.*?', line).group(0))
If you cannot do split
then you can just match the numbers with optional -
or +
at the start:
>>> s = '-30.345 foo 150.930 abc 112.356 another .123'
>>> re.findall(r'([+-]?\d*\.?\d+)', s)
['-30.345', '150.930', '112.356', '.123']