Remove Usernames From Twitter Data Using Python
I have fetched some data from Twitter using python. now I want to pre process it. how can I remove usernames if the tweet has username between two words and there is no space among
Solution 1:
importreTweet="Hello@username"
Tweet = re.sub('@[^\s]+','',Tweet)
This code will remove the @username and Hello will not be removed.
Solution 2:
importreTweet="Hello@username"
Tweet = re.sub('@[\w]+','',Tweet)
Building on @NegiBabu's solution, Twitter only allows alphanumeric handles and so [\w] works as a better regex for this task. For e.g. with my proposed regex you wouldn't allow for @app#le to be matched.
Post a Comment for "Remove Usernames From Twitter Data Using Python"