#hashtags に一致する正規表現を Python で作成しようとしています。ハッシュタグの私の定義は次のとおりです。
- から始まる作品です。
# - を除くすべての文字を含めることができます。
[ ,\.] - テキストのどこでも構いません
なので、本文では
#This string cont#ains #four, and #only four #hashtags.
ここでのハッシュはThis、four、onlyおよびhashtagsです。
私が抱えている問題は、行頭のオプションのチェックです。
[ \.,]+オプションの先頭と一致しないため、実行しません。[ \.,]?似合いすぎてやらない。
+ 付きの例
In []: re.findall('[ \.,]+#([^ \.,]+)', '#This string cont#ains #four, and #only four #hashtags.')
Out[]: ['four', 'only', 'hashtags']
? の例
In []: re.findall('[ \.,]?#([^ \.,]+)', '#This string cont#ains #four, and #only four #hashtags.')
Out[]: ['This', 'ains', 'four', 'only', 'hashtags']
オプションはどのように行頭に一致させることができますか?