0 votes
in JAVA by
Can you write a regular expression to check if String is a number?

1 Answer

0 votes
by
If you are taking Java interviews then you should ask at least one question on the regular expression. This clearly differentiates an average programmer with a good programmer. Since one of the traits of a good developer is to know tools, regex is the best tool for searching something in the log file, preparing reports etc. Anyway, answer to this question is, a numeric String can only contain digits i.e. 0 to 9 and + and - sign that too at start of the String, by using this information you can write following regular expression to check if given String is number or not

Related questions

+2 votes
asked Jan 24, 2020 in JAVA by rahuljain1
+1 vote
asked Jul 27, 2021 in JAVA by SakshiSharma
...