Here is a little function which takes a string and returns an array of hashtags.

If you give:

'#HelloWorld, this is a #test'  

It will return:

['HelloWorld', 'test']

Here the code:

// hasgtag.js:

/* Extract hashtags text from string as an array */
function getHashTags(inputText) {  
    var regex = /(?:^|\s)(?:#)([a-zA-Z\d]+)/gm;
    var matches = [];
    var match;

    while ((match = regex.exec(inputText))) {
        matches.push(match[1]);
    }

    return matches;
}

module.exports = getHashTags;  

And here are the mocha tests:

// test_hashtag.js:

var expect = require('chai').expect;

describe('Test hashtag extracting function', function() {  
    var getHashTags = require('./hashtag.js');

    it('should extract the hashtags', function(done) {
        var input = '#begin foobar #Has #Hell123 #hello and #what, #ending';
        var expectedResult =
            ['begin', 'Has', 'Hell123', 'hello', 'what', 'ending'];

        var result = getHashTags(input);

        expect(result).to.eql(expectedResult);
        done();
    });

    it('should return an empty array', function(done) {
        var input = 'foo bar.';
        var result = getHashTags(input);

        expect(result).to.eql([]);
        done();
    });
});

To run the tests:

$ npm install mocha
$ mocha test_hashtag.js

Note

If you want to test your regular expressions, you can use this tools: http://regex.blaisethirard.com/