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

0

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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]*/)

1 Comment

I used this to get some java. The find() method won't return you a String directly
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];

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.