how to get url from string in java code||

This code is represent by search URL from the giving string or text. It is basic Regex for doing here.
this code is detected www or start with http.

Now the code is giving below.----------


//Pull all links from the body for easy retrieval
private ArrayList pullLinks(String text) {
ArrayList links = new ArrayList();

String regex = "\\(?\\b(http://|www[.])[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(text);
while(m.find()) {
String urlStr = m.group();
if (urlStr.startsWith("(") && urlStr.endsWith(")"))
{
urlStr = urlStr.substring(1, urlStr.length() - 1);
}
links.add(urlStr);
}
return links;

Comments

Popular posts from this blog

Can't import database through phpmyadmin file size too large xampp

incompatible hax module version 3 requires minimum version 4 no accelerator found

how to use text box in android studio