📅  最后修改于: 2022-03-11 15:01:30.005000             🧑  作者: Mango
function replaceURLs(message) {
if(!message) return;
var urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
return message.replace(urlRegex, function (url) {
var hyperlink = url;
if (!hyperlink.match('^https?:\/\/')) {
hyperlink = 'http://' + hyperlink;
}
return '' + url + ''
});
}
replaceURLs("Visit www.cluemediator.com and subscribe us on https://www.cluemediator.com/subscribe for regular updates.")
// Output: Visit www.cluemediator.com and subscribe us on https://www.cluemediator.com/subscribe for regular updates.