Word count using split by count last space

Hi, I am using the split by (space): count
in order to count words in the input text.
However. I have few issues:

  1. It count the space until there is a word following the space.
  2. It count the space in case there is on after the last word.

Any suggestions?
Screenshot 2024-01-08 at 17.12.51

Screenshot 2024-01-08 at 17.12.19

Regex can save you :slight_smile:

Instead of using “:split by ’ ':count” use ":extract with regex (Regex pattern=\b\w+\b):count " This regex finds all word boundaries followed by any number of word characters (digits too) followed by a final word boundary.

It wont be fooled by extra spaces or trailing spaces or any other exception.

Edit:
I ran a few tests and it seems like this regex will actually be fooled by special characters like @,ò,à,Ã,Š etc. Not only does it not recognise them as characters, it doest even add word boundaries around them, so cant rely on it.

Use this:
livetext A’s value: trimmed: extract with regex (Regex Pattern: ‘press the spacebar here and then type in a +’):count

2 Likes

Thanks!
It looks like it doesn’t count words less then 3 characters as a word.
I have tried the regex - (\S+)\s* and it works great!
Thank you for showing the option of regex.

This topic was automatically closed after 70 days. New replies are no longer allowed.