このSOのRegExpを使用して、単語をカットせずに文字列を短縮しています。残念ながら、テストされた文字列に改行がある場合、これは機能しません。単語をカットせずに、また最初の改行の後に文字列を短縮する方法はありますか?
"this is a longish string of \n\n test".replace(/^(.{11}[^\s]*).*/, "$1");
//Expected output: "this is a longish"
//Actual output: "this is a longish test"