Help with regex to detect urls in a string

Posted by Ali Taha Ali Mahboub on Stack Overflow See other posts from Stack Overflow or by Ali Taha Ali Mahboub
Published on 2011-01-04T09:11:31Z Indexed on 2011/01/04 9:54 UTC
Read the original article Hit count: 507

Filed under:
|

Hi guys i found this regex to detect urls in a string and wraps them inside the tag

public static String detectUrls(String text) {
    String newText = text
            .replaceAll("(?<!http://)www\\.[\\w/%.\\-?&=]+", "http://$0")
            .replaceAll("(?:https?|ftps?|http?)://[\\w/%.\\-?&=]+",
                    "<a href='$0'>$0</a>");
    return newText;
}

but this regex doesn't work with the following pattern:

https://www.myserver.com

so please advise.

© Stack Overflow or respective owner

Related posts about java

Related posts about regex