turn text into links javascript
function linkify(inputText) {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
//Change email addresses to mailto:: links.
replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
return replacedText;
}
Also in JavaScript:
- angular transition animation
- js detect all images errors
- refresh data after some time angular
- get current week number javascript
- moment check valid date
- add property to object javascript
- jquery safely use $
- javascript remove object key
- showing file download progress in angular
- how to move up in terminal
- javascript assignment operator if undefined
- Extension server error: Object not found: <top>, source: devtools://devtools/bundled/extensions/extensions.js (216) [9900:1226/171021.620
- jquery get the parent node
- Javascript remove array item by value
- angular usehash not working
- javascript regex Zero or one occurrence
- detect adblock javascript
- sort multidimensional array javascript
- how to deploy node-red as a window service
- petition the lord with prayer
- chartjs lineTension
- nodejs format text
- emit resize event in angular
- append before parent jquery