iOS

Regular Expressions and Shortcuts, Part 3.5

This post is part of a series on Regular Expressions and their applications in the Shortcuts app.

Regular Expressions and Shortcuts, Part 1

Regular Expressions and Shortcuts, Part 2

Regular Expressions and Shortcuts, Part 3

Before continuing on and looking at how to integrate the regular expression we’ve been talking about so far into a shortcut, I want to incorporate a piece of feedback from Allister Jenks.

I originally came up with this:

^(?:.+\/){1,}(.+)\.json$

Allister points out that there’s a much more logical and concise way of doing it.

He’s right, of course. The following works perfectly and makes more sense.

^(?:.+\/)+(.+)\.json$

Actually, we don’t even need the + after the first group, thanks to greedy matching. By …

(Read More)

Regular Expressions and Shortcuts, Part 3

This post is part of a series on Regular Expressions and their applications in the Shortcuts app.

Regular Expressions and Shortcuts, Part 1

Regular Expressions and Shortcuts, Part 2

Hi, it’s me again, the guy with the terrible regular expression that I keep yammering on and on about:

^(?:.+\/){1,}(.+)\.json$

Last time I explained how (.+\/){1,} works to match file path directories in a file name, like these:

hugo-files/data
hugo-files/
hugo-files/data/links/

I did not explain, however, why the first part of the regular expression contains ?: inside the first set of parenthesis, like this:

(?:.+\/){1,}

In order to understand this, you have to understand the role of the parenthesis in regular expressions.

First, they do what I said last time they do: group things together for the purposes of applying a subsequent modifier to everything in the group. In our case, because …

(Read More)

Regular Expressions and Shortcuts, Part 2

Last time, I presented a case in which I wanted to take a list of files complete with file path, and extract just the file name without the extension.

So basically, I get a list of file names that come back like this:

hugo-files/data/links/cars.json
hugo-files/data/links/podcasts.json
hugo-files/data/links/language.json
hugo-files/data/links/apps.json
hugo-files/data/links/security.json
hugo-files/data/links/linux.json
hugo-files/data/links/programming.json
hugo-files/data/links/apple.json

And I want to turn it into the following list instead, by getting rid of the directory paths and the .json file extensions:

cars
podcasts
language
apps
security
linux
programming
apple

I do this in my shortcut using a Match Text action with the following regular expression:

^(?:.+\/){1,}(.+)\.json$

It looks mind-bogglingly weird if you’re not used to regular expressions, and certainly someone skilled with them could probably perform the same task with a much more elegant version, but this does the job for me, and it’s really quite simple. Basically, it looks for strings that match the following: …

(Read More)

Regular Expressions and Shortcuts, Part 1

Today as I worked on finishing up a major revision to my Blog Post Publish shortcut, it occurred to me that, in a relatively short period of time, I went from struggling to understand regular expressions in general, and how regular expressions worked in Shortcuts in particular, to using them all the time in my shortcuts.

I decided I’d start a series about regular expressions and how to use them productively with the Shortcuts app, not because I’m a genius with regular expressions, but to show that anyone can learn them and that they are indeed useful and powerful when used for creating shortcuts.

Regular Expressions

The term “regular expressions” sounds a little odd, but basically regular expressions are just patterns used for searching text. They are extremely useful for things like extracting specific bits of information from text, for replacing specific things in text, or for validating text input for an app or web page.

To be …

(Read More)