I need to be able to detect URIs in some text and after this replace
dem with HTML-anchors, that is
should be replaced with
<a href="http://www.tempuri.org/page.html">http ://www.tempuri.org/page.html</a>
I have made the following code:
re = new RegExp('(((http |https|ftp):\/\/)?\w+[.\w]+([^\w]*[\s]+))');
str = document.forms[0].longtext.value ; //textarea with text to replace
newstr = str.replace(re, '<a href="$1">$1</a>');
document.write( newstr);
However, it doesn't quite work as I would like it to. It seems to only
make a single match, and it seems to ingore leading and trailing
whitespaces.
Can you help me solving this?
I test of the code I have so far can be found at
Thanks,
:o)
--
Jesper Stocholm - http://stocholm.dk
Copenhagen, Denmark
dem with HTML-anchors, that is
should be replaced with
<a href="http://www.tempuri.org/page.html">http ://www.tempuri.org/page.html</a>
I have made the following code:
re = new RegExp('(((http |https|ftp):\/\/)?\w+[.\w]+([^\w]*[\s]+))');
str = document.forms[0].longtext.value ; //textarea with text to replace
newstr = str.replace(re, '<a href="$1">$1</a>');
document.write( newstr);
However, it doesn't quite work as I would like it to. It seems to only
make a single match, and it seems to ingore leading and trailing
whitespaces.
Can you help me solving this?
I test of the code I have so far can be found at
Thanks,
:o)
--
Jesper Stocholm - http://stocholm.dk
Copenhagen, Denmark
Comment