I'm currently attempting to extract hashtags from a text string by splitting it and removing unwanted HTML tags.
Despite my efforts, I haven't been able to achieve the desired outcome. I am seeking guidance on where I might be going wrong.
Here is an example of the text string:
"<a href=\"https://twitter.com/search?q=fnb\" target=\"_blank\">#fnb</a>, <a href=\"https://twitter.com/search?q=mobilesimcard\" target=\"_blank\">#mobilesimcard</a>, <a href=\"https://twitter.com/search?q=what\" target=\"_blank\">#what</a>, <a href=\"https://twitter.com/search?q=refugeechild\" target=\"_blank\">#refugeechild</a>"
This is the code snippet I've written so far:
var str = "<a href=\"https://twitter.com/search?q=fnb\" target=\"_blank\">#fnb</a>, <a href=\"https://twitter.com/search?q=mobilesimcard\" target=\"_blank\">#mobilesimcard</a>, <a href=\"https://twitter.com/search?q=what\" target=\"_blank\">#what</a>, <a href=\"https://twitter.com/search?q=refugeechild\" target=\"_blank\">#refugeechild</a>";
var array = [];
var parts = str.split('target=\"_blank\">', '');
parts.forEach(function (part) {
var rem1 = part.replace('</a>', '');
array.push(rem1)
})
var value = array;
console.log(value);
The expected output should be: #fnb, #mobilesimcard, #what, #refugeechild
It seems that my str.split()
method isn't functioning as intended, and I suspect I may need to improve upon the .replace()
function as well.
Appreciate any assistance you can provide!