I am trying to detect URL inside another string. I got an answer from another SO. However, it does not work for a use case needed by us.
Detect and extract url from a string?
URL_REGEX = "(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)"
+ "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*"
+ "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)";
Pattern p = Pattern.compile(URL_REGEX, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
String str = "hello example.com"; // DOES NOT WORK
//str = "$ANY_WORD example.com $ANY_WORD_1"; // DOES NOT WORK
str = "hello http://example.com"; // WORKS
Can you please modify above regex work for str = "hello example.com"
as well?
Input String can be a combination of many words and urls