我正在编写一个正则表达式来检查一个单词是否以 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)\\://