Skip to content

Instantly share code, notes, and snippets.

@yunusemre002
Created November 12, 2021 14:53
Show Gist options
  • Save yunusemre002/bb8bdf0e4a5d1739f29baa7bddec1c52 to your computer and use it in GitHub Desktop.
Save yunusemre002/bb8bdf0e4a5d1739f29baa7bddec1c52 to your computer and use it in GitHub Desktop.
replace_punctuation_with_space.js
const punctuation = /[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~\s]/g;
preprocessingWord = (word) =>
word
.toLowerCase() // Convert all uppercase to lowercase
.replace(punctuation, ' ') // replace punctuation with space.
.replace(/ +/g, ' '); // Drop excess spaces.
// Example
let text = "BUNDAN SONRA NEFRET... SÖYLEMİ!;., SÖYLENMEYECEKTİR.,,,-."
console.log(preprocessingWord(text));
// output: bundan sonra nefret söylemi̇ söylenmeyecekti̇r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment