My String:
download_recording true Package available http://abc.com/recDownload/635131586215948750.exe
How to get http://abc.com/recDownload/635131586215948750.exe
from the above string?
please help
This blog conatins sample code:
http://blog.houen.net/java-get-url-from-string/
As well as this question:
Detect and extract url from a string?
And this might help as well:
This is a very simple one to match things that include a prefixed protocol.
[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"
Equivalent javascript
'download_recording true Package available http://abc.com/recDownload/635131586215948750.exe click the link'
.match(/[a-z]+:\/\/[^ \n]*/)
Simple use of the split method from the string class should parse this.
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];
I think this regex is what you are looking for:
(http\:\/\/){0,1}(www){0,1}[\.]{0,1}[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\/{1}[a-zA-Z0-9_\.]+)*