0

I am trying to use this nefty regex:

\(?(?:(http|https|ftp):\/\/)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?

Found it here: https://someweblog.com/url-regular-expression-javascript-link-shortener/

It finds URLs and shortens them. But there is a bug. When any 2 characters have a period "." in between it turns into a link. For example if a user forgets puts a space between 2 words... it becomes a URL.

For example: I love stack.overflow very much. stack.overflow will become a link.

And although, Javascript is used in the example. This regex works with VB.net. The one from this question does not: Regex to find URLs in a string

Not a real meerkat
  • 5,604
  • 1
  • 24
  • 55
7huan
  • 105
  • 10

1 Answers1

0

I did not read the latter long expressions, but if you want to force protocol name (e.g. http) always included, you may remove the third '?' from the regex.

akky
  • 2,818
  • 21
  • 31