Pattern Matching and Wildcards

Have you ever found yourself trying to do things depending on some text in the name or the description of a card?

Butler commands support "patterns" and "wildcards". These are often most useful in trigger conditions. Let's see what's this all about.

Trigger conditions are clauses that can be applied to a trigger so that it only fires for cards with certain features. For example:

when a card containing "urgent" is moved to list "Assigned Tasks", copy the card to "My Urgent Tasks" on board "My Master Board" and link the cards together

In this command, the clause containing "urgent" is the trigger condition.

Let's focus on the part of the condition that matches the name of the card against the text "urgent".  That text is what we call the pattern. Here's a more complex example:

when a card with a name ending with "invoice #{*}" is added to "Inbox", add the "Invoice" label to the card and post comment "@board Invoice number {wildcard1} is in this card!"

We've now introduced a wildcard: the special sequence  {*} will match any text, including blank spaces. So, for example, this command will trigger for a card named Attached invoice #0001.

Notice also the  {wildcard1} variable. This variable takes the value of the first (and in this case only) wildcard in the condition pattern. In our example, if would take the value 0001. The command will post a comment saying: @board Invoice number 0001 has arrived!

Patterns can get very complex, with multiple wildcards in one pattern. 


Wildcard Variations

Sometimes, matching any text is not exactly what you need.

The   {* } wildcard (notice an additional blank space in between the asterisk and the closing bracket), matches only until a blank space, or the end of the text, is found. In the example above, for example, it would be useful to use this wildcard if the invoice number was in the middle of the text instead of the end.

Butler also supports what is called a "non-greedy" wildcard:  {?}. As opposed to the "greedy" wildcard {*} , this non-greedy one will end after matching the minimum amount of text. This is best seen with an example:

If the text is  Monday - Tuesday - Wednesday, and the pattern is {*} - {*}, then:

  • {wildcard1} will be Monday - Tuesday
  • {wildcard2} will be Wednesday

If the pattern is  {?} - {*} or {?} - {?}, then:

  • {wildcard1} will be Monday
  • {wildcard2} will be Tuesday - Wednesday

Wildcards in other parts of the command

You can use wildcards not just to match text in the name or description of a card, but also in the names of pretty much every Trello element:

when a card is moved to list "Week {*}" by anyone, post comment "Scheduled for week {wildcard1} on {date} by {username}."

The command above will trigger for any list whose name starts with "Week ".