すべてのハッシュタグ(英数字とアンダースコアとハイフン)のテキストを検索し、検索などのスパンタグでラップするにはどうすればよいですか
some_string = "this is some text with 3 hashtags #Tag1 and #tag-2 and #tag_3 in it"
そしてそれを次のように変換します:
"this is some text with 3 hashtags <span>#Tag1</span> and <span>#tag-2</span> and <span>#tag_3</span> in it"
私はこれまでのところこれを持っています:
some_string = some_string.replace(/\(#([a-z0-9\-\_]*)/i,"<span>$1</span>");
しかし、1 つの欠点は、必要なようにラッピングに # が含まれていないことです。出力されるようです:
"this is some text with 3 hashtags <span>Tag1</span> and #tag-2 and #tag_3 in it "
また、最初に見つかったハッシュタグのみを検出し (例:#Tag1
このサンプル)、すべてを検出する必要があります。
また、ハッシュタグは # の後に最低 1 文字必要です。したがって、 # だけでは一致しないはずです。
ありがとう