Give a regular expression for a certain type of scientific n
Give a regular expression for a certain type of scientific notation for real numbers on which the following rules hold. Let sigma = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \"+\", \"-\", e}. The number can be preceded by a \"+\" or \"-\" sign or the sign may be absent. Numeric values must be of the form cb_1 b_2 ... b_n where b_i is any digit, but c must be nonzero. The number may be followed by an exponent field of the form e\"+\" yy or e\"-\"yy, where y can be any digit.
Solution
The required regular expression is [+-]?[1-9]([0-9])*(e[+-]([0-9]){2})?
Note:
Square brackets [ ] is used to specify a list of possible choices of characters
? indicates optional
* indicates zero or many repetitions of the preceding group
round Brackets ( ) are used for grouping
========================
Let me explain with the requirements
1. number can be preceded by an optional + or - sign . This is done as [+-]?
2. numeric values in the form cbbbb... where c is nonzero is done as [1-9]([0-9])*
3. the optional exponent part of the form e followed by + or - and 2 digits is written as (e[+-]([0-9]){2})?
=================
Hope it answers the question. If yes please dont forget to rate the answer. Thanks
