zoukankan      html  css  js  c++  java
  • JAVA 正则表达式

    最近使用JAVA正则表达式,有个匹配URL的例子很实用,贴出来分享一下!

    文件名称:Test.java

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class Test{
    
        public static void main(String[] args){
            System.out.println(isUrl("http://www.tmall.com/sss.html"));
            System.out.println(isUrl("http://www.baidu.com/sss.html"));
    
        }
    
      /**
         * URL检查<br>
         * <br>
         * @param pInput     要检查的字符串<br>
         * @return boolean   返回检查结果<br>
         */
        public static boolean isUrl (String pInput) {
            if(pInput == null){
                return false;
            }
            String regEx = "^(https?|ftp|file)://[a-zA-Z0-9-_]*.tmall.com/[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
            Pattern p = Pattern.compile(regEx);
            Matcher matcher = p.matcher(pInput);
            return matcher.matches();
        }
    }

    运行结果:

    @~/study $ java Test

    true
    false
  • 相关阅读:
    函数的参数设置
    定义函数
    使用dict和set
    (转)set集合的应用
    循环与range
    if语句
    How to use git hub
    Install pyodbc in OpenSUSE
    Ubuntu编译安装PHP7
    Ubuntu为已经安装的PHP7单独编译mysqli
  • 原文地址:https://www.cnblogs.com/liqiu/p/3401063.html
Copyright © 2011-2022 走看看