package com.t3.util; import java.util.regex.Pattern; public class URLUtil { private static Pattern URL=Pattern.compile( "(\\b(http(s?)\\:\\/\\/|www.)" + "(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" + "|mil|biz|info|mobi|name|aero|jobs|museum" + "|travel|[a-z]{2}))(:[\\d]{1,5})?" + "(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?" + "((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" + "(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" + "(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b)"); public static String replaceUrlsWithLinks(String text) { return URL.matcher(text).replaceAll("<a href=\"$1\">$1</a>").replace("<a href=\"www.", "<a href=\"http://www."); } }