Hashtag RegExp

by kaikemono

HTML

<p>Foo bar #foobar #test</p>
<p>Fosdfo bsdfar #fsdfoobar #test</p>

CSS

.tag {
    color: red;
    font-weight: 700;
}

JavaScript

// hashtag_regexp = /#([a-zA-Z0-9]+)/g;

hashtag_regexp = /#(\s|\A)#(\w+);

function linkHashtags(text) {
    return text.replace(
        hashtag_regexp,
        '<span class="tag">#$1</span>'
    );
}

$(document).ready(function(){
    $('p').each(function() {
        $(this).html(linkHashtags($(this).html()));
    });
});