Help with Regex in an iOS Shortcut

Hello, I have been trying to use regex regex to parse information from a meeting invitation for use in setting up an automatic dialer within iOS. I’m hoping to take a photo of the meeting detail, OCR the photo, pull the relevant information out into variables, and then use those variables to dial the phone number, enter the meeting number, and enter the attendee ID.

The data looks like the following after it has been OCR’d and pulled into iOS Shortcuts.

US Toll
+1-123-456-7890
US Toll Free
+1-987-654-3210
Enter
Access code
321 654 987 #
Attendee ID
65 #

I can get regex to pull in the Access Code (321 654 987) using \d{3} \d{3} \d{3} #.

I’m having trouble getting the phone number and attendee ID. For the phone number, I use \d{3}-\d{3}-\d{4} but this returns both phone numbers. I would like to use the first phone number (US Toll) rather than the second (Toll Free) number).

For the attendee ID, I’m using (\d{2} #) and it returns two results (87 # and 65 #). I would like regex to return the the second result. The first result is just another instance where two numbers are followed by a space and # sign.

I’ve tried (unsuccessfully) to find a way to have regex return the first instance of the phone number and second instance of the attendee #. I’m hoping someone might be able to help. Thanks in advance!

The key to this kind of capturing is to do the following:

  1. Include signal words that are before or after the part you want to capture.
  2. Use parentheses around the part you want to capture.
  3. Use the Get Group From Matched Text action to get just what’s inside the parentheses.

Here’s an example.

2 Likes

Thank you for your help! The advice and example were very helpful in this case and also for a couple of additional shortcuts I was able to create!