
最好的方法是使用正则表达式,如下所示:
public static final String URL_REGEX = "^((https?|ftp)://|(www|ftp)\.)?[a-z0-9-]+(\.[a-z0-9-]+)+([/?].*)?$";Pattern p = Pattern.compile(URL_REGEX);Matcher m = p.matcher("example.com");//replace with string to compareif(m.find()) { System.out.println("String contains URL");}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)