我的字符串:
download_recording true Package available http://abc.com/recDownload/635131586215948750.exe
如何从上面的字符串中获取http://abc.com/recDownload/635131586215948750.exe
?
请帮助
答案 0 :(得分:3)
此博客包含示例代码:
http://blog.houen.net/java-get-url-from-string/
以及这个问题:
Detect and extract url from a string?
这也可能有所帮助:
答案 1 :(得分:1)
这是一个非常简单的匹配包含前缀协议的东西。
[a-z]+:\/\/[^ \n]*
Pattern.compile("[a-z]+:\/\/[^ \n]*").matcher(
"download_recording true Package available http://abc.com/recDownload/635131586215948750.exe click the link"
).find();
//"http://abc.com/recDownload/635131586215948750.exe"
等效的javascript
'download_recording true Package available http://abc.com/recDownload/635131586215948750.exe click the link'
.match(/[a-z]+:\/\/[^ \n]*/)
答案 2 :(得分:0)
从字符串类中简单使用split方法就可以解析它。
String s = "download_recording true Package available http://abc.com/recDownload/635131586215948750.exe";
//We now have the values on either side of where http:// was
String[] splitted = s.split("http://");
//so index 1 is the url and we can just append http:// back on the beginning to get the whole url
String url = "http://" + splitted[1];
答案 3 :(得分:0)
我认为这个正则表达式是您正在寻找的:
(http\:\/\/){0,1}(www){0,1}[\.]{0,1}[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\/{1}[a-zA-Z0-9_\.]+)*