Chris Hannah
My little piece of the internet

Currently Listening

Use Regular Expressions to Return to 140 Character Tweets

As we all know, Twitter is now changing the character limit of a tweet to 280 characters, from the original 140. I’m sure they have reasons, and I’m not here to argue against any of them.

However, if you find yourself wanting to go back to the “old Twitter”, where tweets were short, and we had to abbreviate things when we couldn’t fit all of it in. There is a way to achieve this.

The method is by simply hiding any tweets that do not meet your length preference. The most popular twitter clients for iOS and macOS (Tweetbot, and Twitterrific), have some form of muting feature, which also allow advanced muting with regular expressions.

Some people make use of this to mute certain hashtags, overuse of hashtags or @mentions, and some really advanced things. But for the purpose of checking a tweet length, you just need to see how many characters there are.

And that’s simply:

[\s\S]{MIN_LENGTH, MAX_LENGTH}

You use [\s\S] to match any character, and then use the lengths afterwards to specify a minimum and/or maximum length.

Just to explain it in a bit more detail, the square brackets are a way to define a collection of character matching rules. And the curly braces are sequence quantifiers, that can match minimum, exact, or maximum length of a match.

And then there’s the s and \S.

The \s is used to match a whitespace character, so spaces, tabs, new lines, etc. And the \S is used to match the opposite, all non-whitespace characters, So if you put them together, then you’re going to match every possible character. Which in a scenario like this, is all you need.

The Patterns

So now I’ve explained the scenario, and solution in a bit of detail, I’ll get to the actual regular expression patterns.

In this case, we simply want to hide all tweets that do not fit the old standard of 140 characters in a tweet.

However, we aren’t setting rules, but instead writing patterns to match tweets that will be hidden, we will need to inverse the logic.

Seeing as we only have one parameter – the maximum length we want to see, it will be very easy. Because now we need to say, if a tweet matches these conditions, hide it.

The conditions will be of course, that it is over the limit we set. In this example I will use the old 140 character limit, but you could set your own custom preference using this same method.

If we take that logic and apply it to the simple pattern I mentioned earlier, we can simplify it even further. As we’re not checking a maximum length, that’s irrelevant. We just want to hide anything over a certain amount.

Which leaves us with:

[\s\S]{MIN_LENGTH,}

You still need the comma in there though, as otherwise it will only match if it is the exact same length as the number entered.

Now the last part, the actual number.

Remember, this is not the length that we want to see, but instead the opposite. So if you want to see all tweets that are 140 characters or less, you need to check for anything 141 characters or over. (The same logic also applies to other limits).

So that makes it:

[\s\S]{141,}

Simple!

Using The Patterns in Tweetbot/Twitterrific

So we have the regular expression created, now we just need to make use of it in a twitter client.

Tweetbot is the slightly easier option, as you just need to navigate to Mute filters, and then add a keyword filter. Where you’ll have to type your pattern in, which will enable a regular expression switch, which you will have to tap.

In Twitterrific, it’s somewhat more confusing, but only initially. In this app, the mute feature is called Muffles. And you add a new muffle, to mute tweets just like Tweetbot. However when you navigate to the Muffles section, it doesn’t mention regular expressions, which lead me to initially thought they weren’t supported.

However, you can use them in Twitterrific, it just takes one extra parameter, a pattern title. You specify a RegEx Muffle in the following format:

Title :: Pattern

P.S. I know there is more formatting available, but it’s not relevant here.

So for Twitterrific, you might want to use something like this:

Classic Twitter :: [\s\S]{141,}

And that is it. Now you can hide away from the future, and pretend these long tweets just don’t exist.

Apps Mentioned:

Reply via Email