I\'m effectively trying to do the same as in this question Change #hash tag to link on page load But I think because I\'m getting the string from a jquery objects data-capti
If you code in your question is posted exactly as you use it, you need to assign the result of the caption.replace()
. Just calling .replace()
won't change caption
.
Assuming all you are doing is this:
caption.replace(/#(\S*)/g,'<a href="http://twitter.com/#!/search/$1">$1</a>');
Try using it like this:
caption = caption.replace(/#(\S*)/g,'<a href="http://twitter.com/#!/search/$1">$1</a>');
As per documentation for Replace
:
Returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match.
Off course, if you already have been doing it and you simply didn't post that than the issue is something else.
Let me know if that is the case and I will remove my answer as it then obviously does not apply.
I would go for /#(\S+)/g
to avoid the single #