import re new_float = "[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?" old_float = "[-+]?(\d+(\.\d*)?|\d*\.\d+)([eE][-+]?\d+)?" print re.match('(%s )*' % new_float, '0 0. 0.1 0.1 .1') print re.match('(%s )*x' % new_float, '0.5 ' * 100) print re.match('(%s )*x' % old_float, '0.5 ' * 100)