Regular expressions
Some good learning resources:
Microsoft MSDN
Java
Http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
Others
Http://developer.51cto.com/art/200912/166310.htm
http://luolei.org/2013/09/regula-expression-simple-tutorial/
http://net.tutsplus.com/tutorials/php/regular-expressions-for-dummies-screencast-series/
Http://deerchao.net/tutorials/regex/regex.htm
1. Valid Numbers
Validate if a given string is numeric.
Some Examples:
"0" = True
"0.1" = True
"ABC" = False
"1 A" = False
"2e10" = True
Note:it is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one. This problem is simpler with regular expressions, directly matching strings.
public boolean isnumber (String s) {
if (S.trim (). IsEmpty ())
return false;
String regex = "[-+]?" (\\d+\\.?| \\.\\d+) \\d* (e[-+]?\\d+)? ";
if (S.trim (). Matches (regex))
return true;
else
return false;
}
2.