Write Python Regular Expression for Floating Point Numbers



The following code uses Python regex to match floating point numbers

Example

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()

Output

This gives the output

234.6789
0.45
Updated on: 2020-02-20T05:49:15+05:30

968 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements