Many programming languages use the exponential notation for
Many programming languages use the exponential notation for large floating point constants. For instance, 6.022E23 or 6.022e23 which both stand for 6.022 × 1023, and 1.6e35 which stands for 1.6 × 1035. The notation consists of a numeral followed by a period (.), followed by one or more digits, followed by E or e, followed possibly by , followed by a numberal. Write a regular expression that captures all numbers in exponential notation.
Union/or is denoted by \"+\" symbol. So 0 + 1 means either zero or one.
Concatenation is denoted by writing one Regular expression after the other. (0+1)0 goes to either 00 or 10.
Star \"*\" means zero or more copies. a* means empty, a, aa, aaa, etc. and (0+1)* refers to all binary strings.
Please write the regular expression using these guide lines.
Solution
At first thought, the following regular expression worksout [-+]?[0-9]*\\.?[0-9]*. This defines a floating point number as an optional sign, followed by an optional series of digits (integer part), followed by an optional dot, followed by another optional series of digits (i.e floating point numbers)
case 1: This regular expression considers a sign by itself or a dot by itself as a valid floating point number.
Therefore the much optimized regular expression is [-+]?([0-9]*\\.[0-9]+|[0-9]+)
case 2: Suppose you want numbers to match with exponents, then follow the next regular expression
[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?
case 3: If you want to validate if a particular string holds a floating point number, you\'ll have to anchor the regular expression i.e ^[-+]?[0-9]*\\.?[0-9]+$ or ^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$

