Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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