I am trying to count the number of words in the first line of the clipboard (there are always multiple lines) up to a ":". I think begins as a regex question but I am not sure where to start. Typically, there are 2 or 3 words, a colon, and then some more text. I just need to know how many words come before the colon.
If I can get the text before the colon into a variable, I know I can filter the variable with a word count. But how to select all the text before the variable in the first line?
One of my goals this year was to learn RegEx. It has been a deeply rewarding experience. Each time I think of a new way to try and use it, I am amazed at what it can do.
Because you want "all the text up to the first :" (and assuming there always is a :) you can split the text on the : character, get the first "bit", and count the words in that.
It looks complicated because it's all being done in one line, but breaking it down:
Split the System Clipboard on : and get the first item: %SystemClipboard[1]:% -- you can read more about "Variable Arrays" here
Use the WORDS() function to get the number of words in the first item: WORDS(%SystemClipboard[1]:%) -- more about functions here
Because we're using a function in a text field we have to wrap it in a %Caculate% token: %Calculate%WORDS(%SystemClipboard[1]:%)% -- more about the Calculate token here
I like it! I am assuming there is only one colon per line since she mentioned âtext... a colon... and some more textâ, but it makes sense to use a non-greedy match anyway.