Skip to content

Instantly share code, notes, and snippets.

@adamrosloniec
Last active July 17, 2019 22:51
Show Gist options
  • Save adamrosloniec/d3595e6d3341eee3d9a82362627284d1 to your computer and use it in GitHub Desktop.
Save adamrosloniec/d3595e6d3341eee3d9a82362627284d1 to your computer and use it in GitHub Desktop.
Node - Remove all special characters from file (.txt, text file, etc)
var fs = require('fs');
fs.readFile("file-with-emoji.txt", "utf-8", (err, data) => {
var dataOld = data
var dataNew = dataOld.replace(/[^0123456789aąbcćdeęfghijklłmnńoópqrsśtuvwxyzźżAĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ\ \!\"\#\$\%\&\'\(\)\+\,\.\/\:\;\<\=\>\?\@\[\]\_\`\{\|\}\–\—\‘\’\‚\“\”\„\…\-]/g, '');
fs.writeFile("file-without-emoji.txt", dataNew, (err) => {
console.log("Successfully Written to File.");
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment