0

I am currently using the regex given below to add hrefs to my urls. But recently I got a bug because one of the urls had a full stop after it and the regex added the dot into the link.

(?:https?|ftps?)://[\\w/%.-]+", "<a href='$0'target='_blank'> $0</a> 

So,can it be modfied so that it takes only one dot? I'm using Java.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • Try this :\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])? or this \://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$ – Ashwin Singh Jun 23 '12 at 12:25
  • I edited mine like this and it worked. "(?:https?|ftps?)://[\\w.]+/[\\w]+", " $0 " –  Jun 23 '12 at 21:21
  • possible duplicate of [Convert plain text to HTML text in Java](http://stackoverflow.com/questions/5134959/convert-plain-text-to-html-text-in-java) – orangepips Jun 24 '12 at 03:16

2 Answers2

0

I used this one:

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?

But you can find a lot more here.

Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106
0

I edited mine like this and it worked."(?:https?|ftps?)://[\w.]+/[\w]+"