2

I am using Linkify.WEB_URLS to linkify URLs in text view, but it looks like there's a bug with the regex.

If I am doing this

noteView.setText("go to the website blabla (https://www.test.com/)");
Linkify.addLinks(noteView, Linkify.WEB_URLS);

It linkifies the closing ) too

Here's how it looks like: https://i.stack.imgur.com/XmOuT.png

Is there a way to fix that other than rewriting the regex completely and using the fixed one in my code? Or am I doing something wrong?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Roman C
  • 21
  • 1

1 Answers1

1

The easiest way to get the closing parenthesis out of your link would be to put spaces around it, like this:

noteView.setText("go to the website blabla( http://www.test.com/ )");

You could also make the link look however you like if you wrap it in an anchor tag and then call Html.fromHTML on it, as shown in the solution here: How can I make links in fromHTML clickable? (Android)

Community
  • 1
  • 1
Mel Stanley
  • 375
  • 2
  • 8
  • 1
    The problem is that I am formatting user content and can't modify it in any way. I've seen that just adding a space at the end of every text snippet solves the bug, but that is not something that I can do – Roman C Jul 13 '12 at 23:12
  • The 'add-white-space' work-around worked for me even if I added it to the very end of the text: `String text = "blabla(http://www.test.com/)"; noteView.setText(text + " ");` – dbm May 28 '14 at 10:47