I'm looking at a 'to do' list application that uses JavaScript. One of the functions converts text in to a hyperlink when https, https or ftp is present.
I'd like to expand this so if my text contains # followed by any 5 digit number, that becomes a link as well. The URL should be http://192.168.0.1/localsite/testschool/search.php?id=ID
where ID is the # and 5 digit number.
This is the current Javascript:
function prepareHtml(s)
{
// make URLs clickable
s = s.replace(/(^|\s|>)(www\.([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|"|<|>|\"|<|>|$)/gi, '$1<a href="http://$2" target="_blank">$2</a>$4');
return s.replace(/(^|\s|>)((?:http|https|ftp):\/\/([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|"|<|>|\"|<|>|$)/ig, '$1<a href="$2" target="_blank">$2</a>$4');
};
called using prepareHtml(item.title)
Any idea how I can do this ?
I've worked out regex to match the # and 5 digits is ^#([0-9]{5})
but I'm not sure how to implement this in the function.
Thanks