regexios-shortcut

How to replace a substring only once?


I have the following string:

Log First Meal Time,Twitter,Midday Routines Done,Midday Routines

I want to write a regular expression such that I will get exactly the following:

Log First Meal Time,Twitter,Midday Routines Done,⚡ Midday Routines

How to do it with some Regex that will only match the second occurrence of Midday Routines in this case?

I was replacing the Midday Routines with ⚡ Midday Routines, but it seems iPhone Shortcuts by default replace all occurrences, and I got:

Log First Meal Time,Twitter,⚡ Midday Routines Done,⚡ Midday Routines

I am new to regular expression and I have no ideas...

Please help! Thank you in advance.


Solution

  • In IOS Shortcuts, you should be able to use ICU Regex.

    For Match, use: (Midday Routines)(.*?)\1

    For Replace, use: $1$2⚡ $1