r/tasker•
arjun2502

[help] Regex match.

Help

Scenario 1. Sentence A= Apple has some good phones.

Sentence B= Apple good phones

What I want to do:

  1. Count number of words in sentence B.

Posted Sep 22, 2021, 8:15 AM UTC

07
Rich_D_sr•

If you split the string into an array using a space as a separator, your word count will be in %array(#). See the user guide under variables.

4
DutchOfBurdock•

Use variable search and replace;

Task: Count Words

A1: Variable Set [
     Name: %boo
     To: Apples are great
     Max Rounding Digits: 3 ]

A2: Variable Search Replace [
     Variable: %boo
     Search: \w+
     Store Matches In Array: %many ]

A3: Flash [
     Text: %many(#) ]

The \w will catch single words, the + after means one or more of this type.

4
UnkleMike•

The \w will catch single words, the + after means one or more of this type.

single words a single word character

2
DutchOfBurdock•

I never got why they say word character, as 0-9 are not really word characters 😛

1
UnkleMike•

I don't know either. I would be more inclined to say alphanumeric, but \w matches _ too. I guess as long as we know what it does, it doesn't matter what we call it.

2
DutchOfBurdock•

I'll blame all the old farts on IRC who used to deal with usernames like Django_589 and got all whiney because their regexp was fugly for their karma and lolbots.

1
UnkleMike•

How is sentence A relevant?

1