从一串字符串中匹配URL地址 正则 (可以没有http或https开头)
2017-02-15 16:50
609 查看
import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; public class helloWorld2 { private static final String TRACK_SEPARATE = ","; public static void main(String[] args) { String str = "\t<html>\n" + "\t\t<body>\n" + "\t\t\t<a href=\"http://stackoverflow.com/questions/ask-1-1-1\" / >\n" + "\t\t\t<a href=\"http://stackoverflow.com/questions/ask\" >kkkkkk</a>\n" + "\t\t\t<img width=\"584\" height=\"154\" alt=\"BIGLOBE WiMAX 2+\" src=\"http://img.google.com/images/shopbnr/imax2_160517_584_154\">\n" + "\t\t</body>\n" + "\t</html>"; getStrings(str); } private static void getStrings( String str) { Pattern p = Pattern.compile("((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|((www.)|[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)"); Matcher m = p.matcher(str); ArrayList<String> strs = new ArrayList<String>(); while (m.find()) { strs.add(m.group(1)); } for (String s : strs){ System.out.println(s); } } }
http://stackoverflow.com/questions/ask-1-1-1 http://stackoverflow.com/questions/ask http://img.gpoint.co.jp/images/shopbnr/biglobewimax2_160517_584_154
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8 Process finished with exit code 0
Pattern p = Pattern.compile("((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|((www.)|[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)");
相关文章推荐
- 从一串字符串中匹配URL地址 正则 (可以没有http或https开头)
- js最强的匹配网址-url的正则表达式:匹配www,http开头的一切网址
- JS正则匹配URL网址的方法(可匹配www,http开头的一切网址)
- java获取url内容及正则匹配链接图片地址
- 正则表达式匹配EXCEL地址字符串
- Apache - 模块 - mod_rewrite - RewriteRule - 匹配任意字符串时,可以借助正则表达式的灵活特性
- 在HTTP请求URL后不仅可以传递字符串还可以传递数组
- 没有终结点在侦听可以接受消息的 http://******/Service.asmx。 这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况, 请参见 InnerExc
- 正则表达式匹配EXCEL地址字符串
- 过滤字符串中 url,图片地址的正则表达式
- RewriteRule中的正则表达式需要考虑是否要加上^(匹配字符串开头)
- c#使用正则表达式匹配字符串验证URL示例
- 正则匹配URL地址
- 判断是不是以http:// ftp://和https:// 开头的URL
- php通过正则从字符串中获取所有图片url地址
- VB中用正则表达式判断一个字符串是不是一个URL地址
- 正则表达式,匹配中文字符、手机号、Email地址、网址URL、HTML标记、国内电...
- Java正则表达式--截取网页中的链接中的TITLE和URL,且URL必须以HTTP或HTTPS开头
- 判断地址url是以http://开头的
- ServiceMetadataBehavior 的 HttpsGetEnabled 属性设置为 True,而 HttpsGetUrl 属性是相对地址,但没有 https 基址。