2

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

nhahtdh
  • 52,949
  • 15
  • 113
  • 149
Lokesh
  • 31
  • 1
  • 1
  • 2

4 Answers4

3

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:

How to detect the presence of URL in a string

Community
  • 1
  • 1
sara
  • 3,590
  • 8
  • 36
  • 68
  • 1
    For the first one, you should extract sufficient information from the link to make the answer self-contained (not dependent on checking the link), since links die. For the other two, comments or flagging it as a duplicate would be more appropriate. – Bernhard Barker Aug 27 '13 at 07:41
1

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]*/)
Hashbrown
  • 8,877
  • 7
  • 57
  • 71
  • I used [this](http://stackoverflow.com/questions/600733/using-java-to-find-substring-of-a-bigger-string-using-regular-expression) to get some java. The `find()` method won't return you a `String` directly – Hashbrown Aug 27 '13 at 08:23
0

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];
tom
  • 324
  • 5
  • 15
0

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_\.]+)*

Aashray
  • 2,667
  • 14
  • 22