JSFiddle - React, Tailwind, and code Playground

by tjerabek

JavaScript

var parseHashtag = function (txt) {
    return txt.match(/(#[A-Za-z0-9\-\_]+)/g) || [];
};

var str = "#hashOne #hashTwo #hashThree #hashOne";
var report = parseHashtag(str);

report = report.filter(function(elem, pos) {
    return report.indexOf(elem) == pos;
})

var i, ii = report.length;
for (i = 0; i < ii; ++i) {
    str = str.replace(report[i], '<a href="">'+report[i]+'</a>')
        }
        console.log(str);