# Find all non-whitespace patterns.
list = re.findall("(\S+)", value)
# Return length of resulting list.
value = "To be or not to be, that is the question."
value = "Stately, plump Buck Mulligan came from the stairhead"
value = ""
Method results. I verified that the method counted correctly the number of words in both (trivial) examples. On more complex samples, such as ones involving markup, results may be less accurate.
So The example method does not count "word endings" but rather the words themselves.
A summary. The regular expression based method for counting words does not exactly mirror all word counting implementations. But in practice the results are close.