Huh? Can you type intelligent sentences or have they failed to teach you
that in school?
Yep, sure can. I can even spell it properly - something.
As for code that solves the original question, no. Because NOBODY can
write code that will *reliably* do what was asked. If you had bothered
to read my first reply to this thread - and comprehended it - you would
realize that. But, just for clarity, let me explain it to you once again.
The problem is not in "counting sentences" as that is nothing more than
counting occurences of punctuation. There are several ways to do that,
but they all have problems.
Step 1: What defines the "end of a sentence"? Typically an occurence of
.. ? or ! signifies the end of a sentence.
So, lets count the occurences of . ? or ! within a string of text. As
the RegExp you gave does that:
str.match(/[?!.]/g).length)
The problem is not counting them, its differentiating them from other
forms of use of those punctuation marks. Consider the following sentence:
"The Dr. went to Mr. and Mrs. Jones' house."
Now, how many sentences is that? Its one. But the pattern you gave gives
4. Thats a flaw. The only way around that flaw is to create a list of
all possible abbreviations and either remove them prior to matching, or,
replace them with the non-abbreviated word. It would also be a better
test to check for one of the marks followed by a space.
It is that very flaw that you cannot - reasonably - get around that
prevents one from being able to *reliably* count sentences.
I can do both, you decide which we shall do.