DEV Community

Discussion on: I have a problem, counting words didn't start from 1?

 
ivkemilioner profile image
ivkeMilioner

It is correct. Counting Cyrillic words. But it starts counting from 0 not from 1.

Thread Thread
 
fcrozetta profile image
Fernando Crozetta

check the code i posted above. It has 2 words, but if you print found, it shows only the second word. The length is 1.
So, it starts counting on 1, but for some reason, your regex is skipping the first word. If you have only one word in the paragraph variable, the result is null.

Thread Thread
 
ripaz profile image
Ripaz

You are checking if space exists before word. Since first word doesn't have space before it, it fails to count it.