Using regex and javascript to make links clickable but not overwrite pre-existing links?

Posted by Lexsym on Stack Overflow See other posts from Stack Overflow or by Lexsym
Published on 2012-09-15T19:09:49Z Indexed on 2012/09/15 21:38 UTC
Read the original article Hit count: 224

Filed under:
|
|
|

I need to make links clickable using javascript and I thought regex would be the easiest not to mention fastest way. I want all links to be clickable, and to not rewrite the already clickable links that exist.

Example: 
Here is a link to visit http://www.example.com/page Please take a look <a href="http://www.example.com/page">here</a>.

Becomes: Here is a link to visit <a href="http://www.example.com/page">http://www.example.com/page</a> Please take a look <a href="http://www.example.com/page">here</a>.

Another example: Here is a link to visit http://www.example.com/page Please take a look here: <a href="http://www.example.com/page">http://www.example.com/page</a>

Becomes: Here is a link to visit <a href="http://www.example.com/page">http://www.example.com/page</a> Please take a look here: <a href="http://www.example.com/page">http://www.example.com/page</a>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex