Shortcuts Replace Text - what is valid replace text?

I have a shortcut that tweets what I’m listening to in Overcast. It title cases the episode info string, which is great except in cases like : the or : a or — the, etc etc.

(Example I want to fix: Blurring the Lines 83: the Phishing Event)

My search string finds all such patterns

([\.\:\-\–]) (the|a)

Now I need the replacement text. Using the standard substitution strings doesn’t seem to work. It will take arguments like $1 and $2 but things like \U and \l don’t (they just insert U and l literally into the string).

Anyone know what replacement arguments I can use there in the Replace Text block in Shortcuts?

Yes, I can (and currently do) brute force it by using two blocks, one for “a” and one for “the”, but this offends my sensibilities. :joy:


Alternatively, you can use the Change Case action if you only need to convert the title into title case.

That’s what I’m doing but it results in those edge cases. Unless you mean parse it to split the podcast name out, but even in titles, hyphens and colons exist and capital case still fails.

I could just capitalize every word, but the English pedant in me won’t allow it. :smile:

Shortcuts is using NSRegularExpression behind the scenes which uses ICU regular expressions, which doesn’t support case change modifiers.

You need to split it out and use something less regex-y for that aspect.

Given the breadth of such words in the English language (as I’m sure you realise and was intended, your example does not cover the full range), and the various style guides people follow I’d suggest putting together a second shortcut that splits a text string and “properly” converts it to title case based on your preferences. Then whenever you need to title case something, pass in your string to a run shortcut action and get the perfectly formatted content back.

Hope that helps.

Makes sense. Thanks.