Regular Expression Filtering in Twitterrific 5 (iOS)

What are regular expressions? Why should I use them?

Regular expressions (often abbreviated to regex) are sequences of characters that are often used in searching for patterns in words or phrases. They're a bit difficult to understand at first, but they're very powerful and can be useful for matching for terms that don't just show up in one way. Using them allows you to cover a variety of different permutations of a word or phrase without needing to create separate rules for each variation. To find out more about regular expressions check out the Wikipedia article on them, as well as this site about ICU regular expressions (which we use).

How do I add regular expression muffles and mutes to Twitterrific 5?

Regular expression (or regex) filtering in Twitterrific 5 is slightly different from other apps. These filters need a name that we can refer to them by, so we've come up with some simple syntax for creating them.

There are two parts to our regex filters: a name and the regex rule we filter by. We separate these from one another with two colons (or ::).

So say, for example, you want to mute spammers that offer you free iPhones on Twitter. When adding a new muffle filter in the muffle screen, you'd start with a name, let's say it's "Free iPhone". Then you'd create your rule. Something along the lines of:

want.*a.*free.*iPhone

To create a regex muffle in Twitterrific's muffle view, you'd write it out like this:

Free iPhone :: want.*a.*free.*iPhone

And bingo! Those spammers aren't bothering you anymore. Twitterrific uses ICU format regular expressions to filter tweets by looking at tweet's text body (shortened URLs and whatever you'd normally see in your timeline). Regular expressions have the potential to be very powerful, but they can also be somewhat confusing. To learn more about ICU regular expressions, go here: http://userguide.icu-project.org/strings/regexp.

How do I make my rule’s case-sensitive?

Twitterrific’s muffle rules are case-insensitive by default, but sometimes there are circumstances where the case of the characters matters. As of Twitterrific 5.14.4, you can create a case-sensitive regex pattern by using three colons instead of two (:::) when naming the rule. For example, the following will inadvertently match more tweets than intended, including tweets with the word “got” in them:

Game of Thrones Spoilers :: GoT

However the following rule, spelled with three colons instead of two, will only match tweets that have “GoT” in them with that exact capitalization:

Game of Thrones Spoilers ::: GoT

How complex can regular expression filtering get?

Regex filtering can get quite complex, and can expand to cover a wide variety situations. Say you wanted to filter all hashtags that involve a word or phrase followed by an emoji character. If you're using Twitterrific 5.10, you could write a regular expression like this:

hashtag with emoji :: #[\S]+([\u00ae|\u00a9|\u203C|\u2047|\u2048|\u2049|\u3030|\u303D|\u2139|\u2122|\u3297|\u3299][\uFE00-\uFEFF]?|[\u2190-\u21FF][\uFE00-\uFEFF]?|[\u2300-\u23FF][\uFE00-\uFEFF]?|[\u2460-\u24FF][\uFE00-\uFEFF]?|[\u25A0-\u25FF][\uFE00-\uFEFF]?|[\u2600-\u27BF][\uFE00-\uFEFF]?|[\u2900-\u297F][\uFE00-\uFEFF]?|[\u2B00-\u2BF0][\uFE00-\uFEFF]?|[\x{1F000}-\x{1F6FF}][\uFE00-\uFEFF]?)+

Or, if you're using Twitterrific version 5.11 or later, you could create the same filter as above like this:

hashtag with emoji :: #[\S]+{emoji}+

This regex rule would then filter out all tweets that contained a hashtag composed of text followed by an emoji character.