const text = "This is a #sample text with #multiple #hashtags for demonstration."; const hashtagRegex = /#(\w+)/g; let matches; const hashtags = []; while ((matches = hashtagRegex.exec(text)) !== null) { hashtags.push(matches[1]); } console.log(hashtags); // Output: ["sample", "multiple", "hashtags"]