我的字符串:
download_recording true Package available http://abc.com/recDownload/635131586215948750.exe
如何http://abc.com/recDownload/635131586215948750.exe
从上面的字符串中得到?
请帮忙
这是一个非常简单的匹配包含前缀协议的东西。
[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]*/)
简单地使用 string 类中的 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];
我认为这个正则表达式是你正在寻找的:
(http\:\/\/){0,1}(www){0,1}[\.]{0,1}[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\/{1}[a-zA-Z0-9_\.]+)*