Skip to content

Instantly share code, notes, and snippets.

@wildone
Last active April 30, 2020 04:44
Show Gist options
  • Select an option

  • Save wildone/e255a462e83a0ba718c918327fa0b66f to your computer and use it in GitHub Desktop.

Select an option

Save wildone/e255a462e83a0ba718c918327fa0b66f to your computer and use it in GitHub Desktop.
Convert Strings into Anchor tags using Regex and Javascript
"If you are looking to fix strings that look like urls in text and convert them to ulrs like this https://www.example.ru http://www.example.com www.example.com.au example.co.jp http://blog.example.app http://www.example.com/product http://www.example.com/products?id=1&page=2 http://www.example.com#up http://255.255.255.255 255.255.255.255 http:// www.site.com:8008 you can use Regex in javascript to replace strings with a format of you liking even if a url is at the end of your string like google.com".replace(/((\w+:\/\/\S+)|(\w+[\.:]\w+\S+))[^\s,\.]/mg,'<a href="$&" target="_blank">$&</a>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment