Last active
October 2, 2022 14:58
-
-
Save david-botelho-mariano/231d028b3b18cb3abb31c36f81e56838 to your computer and use it in GitHub Desktop.
remove @username from string using python and regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_links_and_usernames(texto): | |
texto = re.sub('@\S+','',texto) | |
texto = re.sub('http\S+','',texto) | |
return texto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.datasnips.com/59/remove-usernames-http-links-from-tweet-data/ | |
# https://openclassrooms.com/en/courses/6532301-introduction-to-natural-language-processing/6980751-extract-information-with-regular-expression | |
import re | |
texto = """ | |
1 | |
2 | |
aa @john bbb | |
3 | |
@mary | |
4 | |
""" | |
transf = re.sub(r'@[^ ]+', '', texto) | |
print(transf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment