I am getting numeric values from a file. I need to check each of the line contains numeric value only.
Some numeric values contain exponential values and some contain values like 46.
I need to consider all the numbers which do not contain an alpha value in it and load it into db.
The code I wrote, is not considering exponential and number like this 46. or 1.
How do I consider these kind of values has numeric values.
I WROTE THIS CODE AND IT IS NOT WORKING FOR THE ABOVE NUMBERS
WHat I need to change to accept the above type of numeric values.
None of those will match your regular expression. Your use of matches() means that the whole line must match and those items with an E cannot match because of the E. The value "1." cannot match because your regular expression insists on having at least one decimal after the decimal point.
To match all your example values you must add to the reges a term to deal with the E and you must allow zero decimals after the decimal point. Simple enough.
rekha sen wrote:
I have made a change to the method to accept the Exponential values and it is like this,
This method is handling every thing except "1." values.
Please help me in changing the regex to accept numbers like "1." or "100."
Using "[0-9]+" to define what can come after the decimal point says that there must always be at least one decimal character. Change the '+' to a '*' and it says any number of decimal characters which includes none at all!
If you are going to use regex in the future you would do well to put in effort to learn about them.