ここで提示された回答にはいくつかの問題があります。
{tag.strip("#") for tag in tags.split() if tag.startswith("#")}
[i[1:] for i in line.split() if i.startswith("#")]
「#one#two#」のようなハッシュタグがある場合は機能しません
2re.compile(r"#(\w+)")
多くの Unicode 言語では機能しません (re.UNICODE を使用しても)
ハッシュタグを抽出する方法をもっと見たことがありますが、すべての場合に答えているわけではありません
そのため、ほとんどのケースを処理するためにいくつかの小さな Python コードを書きました。わたしにはできる。
def get_hashtagslist(string):
ret = []
s=''
hashtag = False
for char in string:
if char=='#':
hashtag = True
if s:
ret.append(s)
s=''
continue
# take only the prefix of the hastag in case contain one of this chars (like on: '#happy,but i..' it will takes only 'happy' )
if hashtag and char in [' ','.',',','(',')',':','{','}'] and s:
ret.append(s)
s=''
hashtag=False
if hashtag:
s+=char
if s:
ret.append(s)
return set(ret)