URL匹配

思路:
1.先验证url开始部分 https:// 或 http://
2.通过((http|https)😕/)([\w-]+.)+[\w$]+ 匹配域名www.bilibili
3.(/[\w-?=&./]*)? 匹配 /video/BV1Eq4y1E79W?from=search&seid

public class RegExp11 {
    public static void main(String[] args){
        String content = "https://www.bilibili/video/BV1Eq4y1E79W?from=search&seid=9946545262871408175";
        //思路:
        // 1.先验证url开始部分 https:// 或 http://
        // 2.通过((http|https)://)([\w-]+\.)+[\w$]+ 匹配域名www.bilibili
        // 3.(\/[\w-?=&./]*)? 匹配 /video/BV1Eq4y1E79W?from=search&seid
        String regStr = "^((http|https)://)([\\w-]+\\.)+[\\w$]+(\\/[\\w-?=&./]*)?$";//[.?*]表示匹配的就是本身
        Pattern pattern = Patternpile(regStr);
        Matcher matcher = pattern.matcher(content);
        if (matcher.find()){
            System.out.println("满足格式!");
        }else {
            System.out.println("不满足格式!");
        }
    }
}

更多推荐

10.java正则表达式URL匹配