I have the following string:
tweet = "Get $10 worth of AMAL!!\\nThis campaign will be final AirDrop before official release!!\\nhttps://form.run/@airdrop-e\xa0\\n\\nRT please!\\n\\n#amanpuri #AMAL\\n#BTC #XRP #ETH \\n#cryptocurrency \\n#China #bitcoin \\n#\\xe3\\x82\\xa2\\xe3\\x83\\x9e\\xe3\\x83\\xb3\\xe3\\x83\\x97\\xe3\\x83\\xaa"
And I need to cleen it up, but I stuck with getting rid of the symbols at the end of the string aka \\n#\\xe3\\x82\\xa2\\xe3
which are most likely unicode symbols, emoji and new line symbols \\n
Here is what I do:
pat1 = r'@[A-Za-z0-9]+' # this is to remove any text with @ (links)
pat2 = r'https?://[A-Za-z0-9./]+' # this is to remove the urls
pat3 = r'[^a-zA-Z0-9$]' # to remove every other character except a-z & 0-9 & $
combined_pat2 = r'|'.join((r'|'.join((pat1, pat2)),pat3)) # combine pat1, pat2 and pat3 to pass it in the cleaning steps
And I obtain the following output:
get $10 worth of amal nthis campaign will be final airdrop before official release n e n nrt please n n amanpuri amal n btc xrp eth n cryptocurrency n china bitcoin n xe3 x82 xa2 xe3 x83 x9e xe3 x83 xb3 xe3 x83 x97 xe3 x83 xaa
So I still have all these n's and xe3's Can anybody suggest a python regular expression for this purpose? Thx in advance.
These are not characters. They’re escapes. You can match them using this regex:
r'\\(n|x..)'
If you want to remove them, use:
import re
tweet = re.sub(r'\\(n|x..)', '', tweet)