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++;
                    }
    
        }
    
    }

    结果显示

  • 相关阅读:
    7.29 H5学习笔记
    8.1H5学习笔记
    8.4 H5知识点总结
    8.15 CSS知识点6
    8.12 CSS知识点5
    HTTP协议简析(二)
    php实现二分查找法
    http协议简析(一)
    telnet客户端模拟浏览器发送请求
    导入txt文件到SQL SERVER 2008
  • 原文地址:https://www.cnblogs.com/gzbit-zxx/p/7016171.html
Copyright © 2011-2022 走看看