ใช้ Python regex จับคู่ floating point numbers
ตัวอย่าง
import re
s = '234.6789'
match = re.match(r'[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?', s)
print(match.group())
s2 = '0.45'
match = re.match(r'[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?', s2)
print(match.group())
ผลลัพธ์
234.6789
0.45