Created
October 17, 2016 06:31
-
-
Save joelalejandro/6138ff3b2485b65d88c588a607aa81b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function sanitize(tweet) { | |
| let text = tweet.text.replace(/\n/g, '').replace(/RT /g, ''); | |
| tweet.entities.user_mentions.forEach((user) => { | |
| text = text.replace(new RegExp(`@${user.screen_name}(:)?`, 'g'), ''); | |
| }); | |
| tweet.entities.hashtags.forEach((hashtag) => { | |
| text = text.replace(new RegExp(`#(${hashtag.text})`, 'g'), '$1'); | |
| }); | |
| text = text.replace(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi, ''); | |
| text = text.trim(); | |
| return text; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment