문자열의 링크를 찾아서 a 태그로 감싸주기

public static String populateLinks(String str) {
 
	Matcher matcher = Pattern.compile("(https?|ftp)://[\\S]+").matcher(str);
 
	StringBuffer sb = new StringBuffer();
	while(matcher.find()) {
		String link = matcher.group();
		link = link.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\$", "\\\\\\$");
		matcher.appendReplacement(sb, String.format("<a href=\"%s\">%s</a>", link,link));
	}
	matcher.appendTail(sb);
	return sb.toString();
}