I’m using the RegExp from this SO to shorten string without cutting words. Unfortunately this dont work when there are line breaks in the tested string. Is there a way to shorten string without cutting words and also after at the first line break.
"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"
Have you tried inserting another ‘.replace()’ before the one you’ve got?
Example:
Perhaps something to that effect will help? You may need to play with the formatting a little, as I’m not sure how you want the string to actually end up looking, or how the
<br>tags in your page are formatted, etc.Good luck!