Snippet de exibição de JA da string de texto
function getSnippet(text, length) {
var rx = new RegExp("^.{" + length + "}[^ ]*");
return rx.exec(text)[0];
}
console.log(getSnippet("get snippet text using javascript?", 1)); // get
console.log(getSnippet("get snippet text using javascript?", 3)); // get
console.log(getSnippet("get snippet text using javascript?", 10)); // get snippet
console.log(getSnippet("get snippet text using javascript?", 11)); // get snippet
Borma