获取url路径的正则

package unit;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Util {
    // 获取url路径的正则
    private static final String URL_REG = "<a .* href=.*[^.exe.*]</a>";

    /**
     * 正则表达式获取链接
     * @return
     */
    public String getHref(String str) {
        Pattern pattern = Pattern.compile(URL_REG);
        Matcher matcher = pattern.matcher(str);
        if (matcher.find())
            return matcher.group(0);
        return null;
    }
}
时间: 2024-07-31 17:03:39

获取url路径的正则的相关文章

js获取url路径包括正则匹配规则来获取

常规获取方法: var protocol = window.location.protocol;  // "http:" var host = window.location.host;  //"localhost" or "www.baidu.com" var pathname = window.location.pathname;  // "/dkrl/services/cases.php" var href = wind

获取url路径中的参数

简介 运用js的时候,我们有时可能会有这样的需求,就是想要获取浏览器地址栏指定的一项参数,形如:https://i.cnblogs.com/EditPosts.aspx?postid=8628413&update=1, 你想要获取postid的内容8628413,或者update的内容1,那么下面就提供解决办法. 解决办法 其实解决办法也挺简单,只要通过一个函数就可以处理掉 //当前url地址栏 file:///C:/Users/admin/Desktop/test.html?id=2 func

jsp获取url路径的方法

如果你请求的URL是  http://localhost:8080/demo/Index.jsp request.getScheme() //输出:http request.getServerName() //输出: localhost request.getServerPort() //输出: 8080 request.getContextPath() //输出: /demo request.getRequestPath() //输出: /Index.jsp request.gerReques

JS获取url参数及url编码、解码

完整的URL由这几个部分构成:scheme://host:port/path?query#fragment ,各部分的取法如下: window.location.href:获取完整url的方法:,即scheme://host:port/path?query#fragment window.location.protocol:获取rul协议scheme window.location.host:获取host window.location.port:获取端口号 window.location.pa

PHP用正则批量替换Img中src内容,用正则表达式获取图片路径实现缩略图功能

PHP用正则批量替换Img中src内容,用正则表达式获取图片路径实现缩略图功能 网上很多正则表达式只能获取或者替换一个img的src内容,或者只能替换固定的字符串,要动态替换多个图片内容的试了几个小时才解决. /*** 图片地址替换成压缩URL* @param string $content 内容* @param string $suffix 后缀*/function get_img_thumb_url($content="",$suffix="!c550x260.jpg&q

PHP用正则匹配获取URL中的域名

在PHP的官网上看到的parse_url()函数的替代方案.结果和parse_url()函数差不多,是使用正则实现的. URI 是 Web上可用的每种资源 - HTML文档.图像.视频片段.程序等 - 由一个通用资源标志符(Uniform Resource Identifier, 简称"URI")进行定位. 对象分组: ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? 12 3 4 5 6 7 8 9 测试代码如下:豪享

JS分页 + 获取MVC地址栏URL路径的最后参数

1 @{ 2 Layout = null; 3 } 4 5 <!DOCTYPE html> 6 7 <html> 8 <head> 9 <meta name="viewport" content="width=device-width" /> 10 <title>AjaxPage</title> 11 <script src="/Scripts/jquery-1.7.1.js&q

从request获取各种路径总结 request.getRealPath(&quot;url&quot;)

转载:http://blog.csdn.net/piaoxuan1987/article/details/8541839 equest.getRealPath() 这个方法已经不推荐使用了,代替方法是: request.getSession().getServletContext().getRealPath() 从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 S

java获取项目路径,url路径

我的web项目名iamgeModel. 工作空间在D盘 先获取url相关: 需要是HttpServletRequest request; 获取IP: request.getServerName() //服务器地址 获取端口: request.getServerPort() //端口号 获取项目名(out:表示结果): request.getContextPath() // out:/imageModel 获取请求完整url路径: request.getRequestURI();// out: /