question: public static String linkHTML ( String text ) { if ( text == null || text . length ( ) == 0 ) { return "" ; } boolean http = text . indexOf ( "http" ) != - 1 ; boolean www = text . indexOf ( "www." ) != - 1 ; boolean email = text . indexOf ( "@" ) != - 1 ; if ( ! http && ! www && ! email ) { return text ; } if ( text . indexOf ( "<" ) != - 1 && text . indexOf ( ">" ) != - 1 ) { return text ; } if ( http ) { Matcher matcher = httpRegex . matcher ( text ) ; StringBuffer sb = new StringBuffer ( ) ; while ( matcher . find ( ) ) { String url = matcher . group ( ) ; if ( url . indexOf ( ".png" ) != - 1 || url . indexOf ( ".jpg" ) != - 1 || url . indexOf ( ".jpeg" ) != - 1 || url . indexOf ( ".gif" ) != - 1 ) { url = "<a href='" + url + "' target='_blank'><img src='" + url + "' height='50'></a>" ; } else if ( url . indexOf ( ".mp4" ) != - 1 || url . indexOf ( ".webm" ) != - 1 || url . indexOf ( ".ogg" ) != - 1 ) { url = "<a href='" + url + "' target='_blank'><video src='" + url + "' height='50'></a>" ; } else if ( url . indexOf ( ".wav" ) != - 1 || url . indexOf ( ".mp3" ) != - 1 ) { url = "<a href='" + url + "' target='_blank'><audio src='" + url + "' controls>audio</a>" ; } else { url = "<a href='" + url + "' target='_blank'>" + url + "</a>" ; } matcher . appendReplacement ( sb , url ) ; } matcher . appendTail ( sb ) ; text = sb . toString ( ) ; } else if ( www ) { Matcher matcher = wwwRegex . matcher ( text ) ; StringBuffer sb = new StringBuffer ( ) ; while ( matcher . find ( ) ) { String url = matcher . group ( ) ; matcher . appendReplacement ( sb , "<a href='http://" + url + "' target='_blank'>" + url + "</a>" ) ; } matcher . appendTail ( sb ) ; text = sb . toString ( ) ; } if ( email ) { Matcher matcher = emailRegex . matcher ( text ) ; StringBuffer sb = new StringBuffer ( ) ; while ( matcher . find ( ) ) { String address = matcher . group ( ) ; matcher . appendReplacement ( sb , "<a href='mailto://" + address + "' target='_blank'>" + address + "</a>" ) ; } matcher . appendTail ( sb ) ; text = sb . toString ( ) ; } return text ; }
target:  Replace links with HTML links. Includes http, www, images, video, audio, email address.