Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clean Text Pasted From Microsoft Word
function cleanstring(dirty){
var smartchr = [ "’","‘","“","”","–","—","…", " ", '„', '‚' , '«','»', '‹', '›'];
var correctchr = ["'", "'", '"', '"', '-', '-', '...', '', '"', "'", '"', '"', "'", "'"];
var thestring = dirty;
var regex;
for (var i = 0; i < smartchr.length; i++) {
regex = new RegExp(smartchr[i], "g");
thestring = thestring.replace(regex, correctchr[i]);
}
return thestring;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.