I found the following code online, but it doesn't work exactly like I need it to. It only passes the domain name as "$1" instead of the whole URL. result=result.replace(/(http\:\/\/[\w\.\-\?\!\&\=]+)/g,'<a href="$1">[LINK]</a>'); Code (markup): Example: http://forums.digitalpoint.com/faq.php?faq=rules Converted with the code above would look like: <a href="http://forums.digitalpoint.com">[LINK]</a>/faq.php?faq=rules
Try this: result=result.replace(/(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/g,'<a href="$1">[LINK]</a>'); Code (markup):
i just noticed a URL that broke the expression. the URL had periods (.) in it and they weren't included on the href. can you change the expression to include periods?
Hi, sorry it didn't work for you. You can try searching regexlib.com for other URL regexes. (regexlib.com/Search.aspx?k=url&c=-1&m=5&ps=20)