Parsing a tweet to extract hashtags into an array

前端 未结 9 734
旧时难觅i
旧时难觅i 2020-12-03 05:33

I am having a heck of a time taking the information in a tweet including hashtags, and pulling each hashtag into an array using Python. I am embarrassed to even put what I

9条回答
  •  眼角桃花
    2020-12-03 06:00

    The best Twitter hashtag regular expression:

    import re
    text = "#promovolt #1st # promovolt #123"
    re.findall(r'\B#\w*[a-zA-Z]+\w*', text)
    
    >>> ['#promovolt', '#1st']
    

提交回复
热议问题