Assuming your string is as below you can use regex as below to extract www.google.com and http://android.com.
String s = "Hello dilip refer this url www.google.com. hi ramesh this is good for android http://android.com";
Pattern pc = Pattern.compile("((http://)|(www.))[A-Z,a-z]+.com");
Matcher matcher = pc.matcher(s);
while(matcher.find())
{
System.out.println("String Extracted "+matcher.group());
}
Output
String Extracted www.google.com
String Extracted http://android.com
Note: The above does not work for these kind of urls http://meta.stackoverflow.com ,www.google.co.uk and b3ta.com.
Edit:
String s = "Hello dilip refer www.google.co.uk www.google.co.in this url www.google.com. hi ramesh this is good for android http://android.com hello there meta.stackoverflow.com";
Pattern pc = Pattern.compile("((http://)|(www.))([A-Z,a-z,0-9])+((.com)|(.co.[a-z]{2}))|([A-Z,a-z,0-9].[A-Z,a-z,0-9])+.com");
Matcher matcher = pc.matcher(s);
while(matcher.find())
{
System.out.println("String Extracted "+matcher.group());
}
Output:
String Extracted www.google.co.uk
String Extracted www.google.co.in
String Extracted www.google.com
String Extracted http://android.com
String Extracted meta.stackoverflow.com
Even the above is not perfect. But if you can modify the above regex it should help you