diff --git a/index.js b/index.js index e2c1059..efc0654 100644 --- a/index.js +++ b/index.js @@ -16,14 +16,15 @@ text = text .replace(/<[^>]+>/g, "") // Strip tags - .replace(/[,:;()\-]/, " ") // Replace commans, hyphens etc (count them as spaces) - .replace(/[\.!?]/, ".") // Unify terminators - .replace(/^\s+/,"") // Strip leading whitespace - .replace(/[ ]*(\n|\r\n|\r)[ ]*/," ") // Replace new lines with spaces - .replace(/([\.])[\. ]+/,".") // Check for duplicated terminators - .replace(/[ ]*([\.])/,". ") // Pad sentence terminators - .replace(/\s+/," ") // Remove multiple spaces - .replace(/\s+$/,""); // Strip trailing whitespace + .replace(/[,:;()\-]/g, " ") // Replace commans, hyphens etc (count them as spaces) + .replace(/[\.!?]/g, ".") // Unify terminators + .replace(/^\s+/g,"") // Strip leading whitespace + .replace(/[ ]*(\n|\r\n|\r)[ ]*/g," ") // Replace new lines with spaces + .replace(/([\.])[\. ]+/g,".") // Check for duplicated terminators + .replace(/[ ]*([\.])/g,". ") // Pad sentence terminators + .replace(/\s+/g," ") // Remove multiple spaces + .replace(/\s+$/g,"") // Strip trailing whitespace + .replace(/'/g,""); // Strip apostrophe text += "."; // Add final terminator, just in case it's missing.