I'm on a mission to find specific keywords within text.
const matchHashtags = /(#\w+) ?/g;
const text ="this is #sample tag and other #another tag";
while ((hashtag = matchHashtags.exec(text))) {
alert(hashtag);
}
Above, we successfully searched for words starting with #. Now, let's try finding words starting with "iphone~" below.
const matchHashtags2 = /(^|\s)\iphone~(\w+)/g;
const text2 ="I have iphone~seven~new and iphone~seven~ old phones";
while ((hashtag2 = matchHashtags2.exec(text2))) {
alert(hashtag2);
}
I expect this query to find "iphone~seven" including the word after it. However, it returns: "iphone~seven, ,seven".
https://jsfiddle.net/gecj54a3/1/
Please help me resolve this issue. Thank you!