Regex to Match or Replace text including line breaks in Shortcuts action

I have the result of a Get Contents of URL action that has multiple lines of texts separated by newlines. I want to isolate one string for further use in the Shortcut. What is the most efficient way to do this? I have tried to Replace all text up to (actually including) the string with:
.*string and replacing that with string but that does not match all the newlines preceding the string so it fails. Is there a way to get . to match newlines? Is there some other trick?

Perhaps you could post some sample text along with details of which line you want to match, specifically what it is in general terms about that line that identifies it.


  • Always the 5th line.
  • Always the line that starts xyz.
  • Always the first line that contains abc.

Sure. I will show the newlines with \n for clarity.

First line\n
line with a string of interest preceded by xxx $99,999,999.99 some more text \n
More lines \n

I would like to have an action that returns the string “$99,999,999.99“
You can assume that the string “xxx” is unique.

ihf, with some Regex flavors, flags can be used — in this case /s would be appropriate. But as far as I know, there’s no way to include Regex flags with shortcut actions. However, the methods in this example might work for you.

Updated 2020-08-06: Below sylumer shared the proper syntax for Regex flags. With that information, I updated my example. It includes this summary page.

See if this shortcut does the sort of thing that you need,

ICU, which is the flavour of rgex that Shortcuts uses, does support a (small) set of regex flags. It’s actually not changed since the first version of Workflow. Here’s a quick regex example I put together for you to show a couple of ways I’ve used them in the past.

It has some sample text and a sample regex. You can then opt to add no flags, the multiline flag, or the dot all flag and see how it affects the results.

Interestingly there’s a case insensitive flag, but I think that must be enforced behind the scenes by Shortcuts.

sylumer, thanks for the information and demonstrating the correct syntax for Regex Flags! I’m going to modify my post above and include a link to a corrected shortcut. It now includes two methods that should achieve ihf’s objective.

This is a perfect example of what’s so great about this forum: I reached out to help someone, and I ended up learning from someone else.

Sorry for my delay in responding. You solved my immediate problem and then some. Thanks @sylumer and @jim_sauer. Once upon a time, many years ago, I programmed in Snobol (and Spitbol) which are designed for pattern matching but I have yet to master the intricacies of regex (especially within Shortcut actions).