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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -