Skip to content

Instantly share code, notes, and snippets.

@arelthia
Created July 16, 2014 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arelthia/6a682366b7bf7a66331d to your computer and use it in GitHub Desktop.
Save arelthia/6a682366b7bf7a66331d to your computer and use it in GitHub Desktop.
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