I'd like to highlight long sentences (say, 50 words or greater) contained in an array of paragraph objects on a page, ie $("#content p")
. I'm not sure how to tackle this.
I originally tried to highlight all sentences, but ran in trouble when they contained HTML tags (example highlighting code on the net seem to be for individual words only, so they don't take child nodes into account). I'm aware that splitting sentences is difficult; I'd like to use .!? followed either by a space then a capital letter or nothing at all (ie the end of the paragraph).
Thanks in advance for any help/advice.
As you've said it's gonna be tricky to get right, given the fact you;re not going to catch them all, I'd stick with something simple like:
var regex = \[^.!?]{50,}[.!?]\;
Getting too clever and you will end up spending more time coding for edge cases than I guess you would reasonably want to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With