Skip to content

Instantly share code, notes, and snippets.

@joshstovall
Created September 10, 2021 09:27
Show Gist options
  • Save joshstovall/44284adc49ac6dedd6be87d450df7773 to your computer and use it in GitHub Desktop.
Save joshstovall/44284adc49ac6dedd6be87d450df7773 to your computer and use it in GitHub Desktop.
function cleanTweet(e){
return e.text
.replace(/\n|\r/g, "")
.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '') // remove URLs
.replace(/\@[^\s]*/g, "") // remove @ mentions
.replace(/\$[^\s]*/g, "") // remove $ cashtags
.replace(/\#[^\s]*/g, "") // remove # hashtags
.replace('RT', '') // replace RT in retweet tweets
.replace('NEW', '')
.replace('// // ', '')
.replace('- ', '')
.trim() // remove extra whitespace
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment