Number of words of a String in a WebL program

I was searching for an easy way to count the words of a given String in a WebL program. WebL is considered as outdated, so it was difficult to find information online.
1 answer

Number of words of a String in a WebL program

I found the solution after browsing through different official samples.
First I get the text content of the node with the method Text(). Then I split the String using the method Str_Search() and a regular expression. The size of the resulting array is the number of the words plus one.

And here is my solution:
PrintLn ("Number of words: ", Size(Str_Search(Text(articleFont[0]), "[0-9a-zA-Z’]+")) - 1);