The regular expression of Leetcode-RegExp

Source: Internet
Author: User
Tags regular expression trim

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.