To extract hashtags and mentions from tweets, you can use simple regular expressions. Here’s how you can do it in Python:
Output:
This function:
-
Extracts hashtags using
#w+, which matches#followed by one or more word characters. -
Extracts mentions using
@w+, which matches@followed by one or more word characters.
Would you like this to work across a list of tweets or in another programming language?
Share this Page your favorite way: Click any app below to share.