zoukankan      html  css  js  c++  java
  • java 正则学习

    前言

    在网上找了许多关于正则解析 URL,结果不是很满意,所以自己学习正则:

    java url

    那么解析 url 的代码如下:

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    
    public class Regex {
    
        public static void main(String[] args) {
            String ee="http:\/\/([\w-]+\.)*[\w-]+\.[\w-]+(\/[\w-]+)*\/[\w-]+\.(html|css|ico)";
            String dd="http:\/\/([\w-]+\.)*\w+\.\w+(\/\w+)*\/\w+\.(html|css|ico)";
            String d="http:\/\/([\w-]+\.)*\w+\.\w+([\w-]+\.)*\/\w+\.html";
            Matcher m = Pattern.compile(ee)
                      .matcher("sss   http://ww-w.sohu.com/fx-y/index.html fff  <link rel="Stylesheet" type="text/css" href="http://static.blog.csdn.net/skin/default/css/style.html?v=1.1" />  <link id="RSSLink" title="RSS" type="application/rss+xml" rel="alternate" href="/allwefantasy/rss/list" /><link rel="shortcut icon" href="http://c.csdnimg.cn/public/favicon.ico" /><link type="text/css" rel="stylesheet" href="http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/default.css" />");
                while(m.find())
                      System.out.println(m.group());
                int i = 0;
                while(m.find(i)) {
                      System.out.print(m.group() + " ");
                      i++;
                    }
    
        }
    
    }

    结果显示

  • 相关阅读:
    MySQL批量更新字段url链接中的域名
    巧用Win+R
    斯坦福高效睡眠法
    chkconfig: command not found
    Nginx(./configure --help)
    Ubuntu16.04配置Tomcat的80端口访问
    Binary Tree Level Order Traversal
    java——Arrays.asList()方法
    python 发送邮件
    常用邮件协议
  • 原文地址:https://www.cnblogs.com/gzbit-zxx/p/7016171.html
Copyright © 2011-2022 走看看