JSFiddle - React, Tailwind, and code Playground

JavaScript

var s = "#hallo, this is a test #john #doe";
var re = /(?:^|\W)#(\w+)(?!\w)/g, match, matches = [];
while (match = re.exec(s)) {
  matches.push(match[1]);
}
alert(matches);