Skip to content

Instantly share code, notes, and snippets.

@joelalejandro
Created October 17, 2016 06:31
Show Gist options
  • Select an option

  • Save joelalejandro/6138ff3b2485b65d88c588a607aa81b2 to your computer and use it in GitHub Desktop.

Select an option

Save joelalejandro/6138ff3b2485b65d88c588a607aa81b2 to your computer and use it in GitHub Desktop.
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