zoukankan      html  css  js  c++  java
  • 常用的正则表达式

    "^[0-9]*[1-9][0-9]*$"  //正整数   
    "^((-\d+)|(0+))$"  //非正整数(负整数 + 0)   
    "^-[0-9]*[1-9][0-9]*$"  //负整数   
    "^-?\d+$"    //整数   
    "^\d+(\.\d+)?$"  //非负浮点数(正浮点数 + 0)   
    "^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"    
    //正浮点数   
    "^((-\d+(\.\d+)?)|(0+(\.0+)?))$"  //非正浮点数(负浮点数 + 0)   
    "^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"    
    //负浮点数   
    "^(-?\d+)(\.\d+)?$"  //浮点数   
    "^[A-Za-z]+$"  //由26个英文字母组成的字符串   
    "^[A-Z]+$"  //由26个英文字母的大写组成的字符串   
    "^[a-z]+$"  //由26个英文字母的小写组成的字符串   
    "^[A-Za-z0-9]+$"  //由数字和26个英文字母组成的字符串   
    "^\w+$"  //由数字、26个英文字母或者下划线组成的字符串   
    "^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"    //email地址   
    "^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$"  //url   
    "^[A-Za-z0-9_]*$"s

    例子:

    判断字母和数字

        public boolean isAllowed(String str)
        {
            if(str.length() >= 6 && str.length() <= 12 ){
                Pattern pattern = Pattern.compile("^[A-Za-z0-9]+$");
                return pattern.matcher(str).matches();
            }
            else return false;
        }

    判断整数

    public boolean isNumber(String str) {
                Pattern pattern = Pattern.compile("^[-\+]?[\d]*$");
                return pattern.matcher(str).matches();
            }
  • 相关阅读:
    UE 不生成.bak文件
    DOTWeen 使用
    unity admob
    UGUI 判断元素进入舞台
    unity 解决ScrollRect嵌套滚动问题
    oc字符串与c字符串转换和拷贝
    Object-c中的单例
    JAVA比较两个List集合的方法
    CentOS 7 配置静态IP
    CentOS7安装Jdk1.8
  • 原文地址:https://www.cnblogs.com/a8047/p/14159421.html
Copyright © 2011-2022 走看看