I have a line containing a link.
ex. line:
We love eating choco, eat it at http://t.co/9BDZvcx59d .
So, if I show this line as is, it will be the same. But if I use a match and pattern to detect the link and color it, it will shorten it.
It will be: Bold is green.
We love eating choco, eat alone at http://t.co .
Pattern urlPattern = Patterns.WEB_URL;
Matcher m = urlPattern.matcher(sb.toString());
sb = new StringBuffer(sb.length());
while (m.find()) {
m.appendReplacement(sb, "<font color=\"#006600\">" + m.group(1) + "</font>");
}
m.appendTail(sb);
I also tried using
Pattern linkPattern = Pattern.compile("(http[A-Za-z0-9_-+)");
But failed to insert: or // into [].
source
share