正则表达式用于检查是否以http://、https://或ftp://开头

15 浏览
0 Comments

正则表达式用于检查是否以http://、https://或ftp://开头

我正在构建一个正则表达式来检查一个单词是否以http://https://ftp://开头,我的代码如下:

public static void main(String[] args) {
    try{
        String test = "http://yahoo.com";
        System.out.println(test.matches("^(http|https|ftp)://"));
    } finally{
    }
}

它打印出false。我还查看了stackoverflow上的帖子Regex to test if string begins with http:// or https://

正则表达式似乎是正确的,但为什么没有匹配呢?我甚至尝试了^(http|https|ftp)\://^(http|https|ftp)\\://

0