Search and Replace Using RegEx

I am having trouble getting a Search and Replace with RegEx to work and am completely baffled.

I am working with the following test macro:

Bank Log Test Macro.kmmacros (8.1 KB)

The first RegEx works as it should and results in the Local_BankPath being set to ~/Documents/Keyboard Maestro/Logs/PDF Logs/{StatementDate}_bank balances.log

The second RegEx is supposed to replace {StatementDate} with Local_MonthEnd which is 20260331 but consistently fails (i.e., does nothing).

Would appreciate help in getting this to work as well as understanding why it does not work particularly given that I tested teh regular expression in RegExr and it worked perfectly!

Thank you.

It seems to work here, starting at the point at which you have said the first regex works:

I know that's not a lot of help, but it indicates to me that maybe the first regex isn't doing exactly what you expect, so the string isn't correct for the second regex. If you display it with surrounding text, i.e....

###%Variable%local_BankPath%###

...do you see any extra blank lines between the delimiters?

-rob.

@griffman , appreciate you testing it and confirming it was properly designed.

I tried starting it where you did (after the first RegEx) and still no joy! I even typed in the file path to make sure there were no extra characters.

I then decided to delete the Search and Replace by Regex and reinstall it and bingo it startedt o work. I have no idea how / why but it is now working and I will monitor it.

Because the search string in the macro you uploaded is:

\{StatementDate\}
\{StatementDate\}
\{StatementDate\}\{StatementDate\}
\{StatementDate\}\{StatementDate\}
\{StatementDate\}

It's always a good check to put the insertion point in your search text and then ⌘A -- if you've more than one line in there the entire field will highlight:

...whereas you wanted to see:

Appreciated.

I wonder how that happened but a great lesson.

The best practice which I will adopt will be to always ⌘A → ⌘C → ⌘V and check the clipboard to make sure the expression is correct, I wasted 1 hour on this last night. :angry:

Thank you.

This little glitch has bitten a lot of us (repeatedly) over the years. We have asked Peter to include some kind of indicator to show that a text field has more than one line, but it's unclear at this point if that feature will appear or not.

-rob.

Glad to know that I am in excellent company.

Wonderful idea, I hope it gets implemented!