regex - Turning text with # symbols into links in javascript -
i wondering how following using javascript.
suppose had text following
var test = '#test #cool #place';
and want following
<a href="abc.html?q=test">#test</a> <a href="abc.html?q=cool">#cool</a> <a href="abc.html?q=place">#place</a>
how that?
i better:
stringtomatch.replace(/(<a[^>]*)?#(\w+)(?!\w)(?!.*?<\/a>)/g, function($0, $1, $2) { return $1 ? $0 : '<a href="'+ window.location +'?q=' + $2 + '">#' + $2 + '</a>'; } ));
this match except other links. see example.
Comments
Post a Comment