繁体   English   中英

正则表达式匹配模式与java中的子域

[英]Regex to match pattern with subdomain in java

我正在尝试匹配子域和域。 我用这个代码。

public static void main(String[] args) {
        String s = "http://aaa.example.com";
        Pattern pattern = Pattern.compile("http://([a-z0-9]*.)example.com");
        Matcher matcher = pattern.matcher(s);
        if (matcher.find()) {
            System.out.println("match");
        }

    }

这适用于http://aaa.example.com以及http://aaa.example.commm 需要匹配example.com更新的子域名:感谢您的答案,它现在有效,我正面临另一个问题,这个正则表达式不匹配http://example.com

使用matcher.matches()而不是find()。 匹配将使整个区域与模式匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM