Regular Expression


  • 0

    Maybe someone is looking for a regular expression solution for this problem

    import java.util.regex.Pattern;
    
    public class Solution {
        public boolean isNumber(String s) {
            if (s == null) {
                return false;
            }
            s = s.trim();
    
        Pattern pattern = Pattern.compile("[+-]?((\\d+\\.?\\d*)|(\\d*\\.?\\d+))(e[+-]?\\d+)?");
            return pattern.matcher(s).matches();
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.