Change Case in Regular Expression Search Replacement Text

I am new to the forums, so I apologize if this has been posted before and I didn’t find it.

I would like to know whether Keyboard Maestro’s search-and-replace regular expressions support changing case in replacement text. I have a macro that runs through the text on the clipboard performing a variety of search-and-replace operations using regular expressions. For some of them, I would like for it to change the case of text in a capture group in the replacement text. The standard regular expression operators to change case (\u, \U, \l, etc) do not seem to work in Keyboard Maestro. Is there a way to get Keyboard Maestro to do this?

For example,

This search expression:

Apt\. ([0-9]*)([a-z]*)$

Would match this text:

Apt. 2g

And this replacement expression:

Apt. $1\U$2

should result in this replacement:

Apt. 2G

Is that possible?

Thanks,
Drew

Hey Drew,

Nope. The ICU regex library in OSX does not support the case-change operator. (Damn it.)

(The Help Menu in the KM Editor contains a link to the syntax page.)

You can always shell-out to Perl, Python, or Ruby, but I usually use AppleScript and the Satimage.osax for jobs like that. It only supports \u and \l, but those usually get me by.

Best Regards,
Chris

Hi, Chris,

Thanks very much for your response. I had seen the syntax page, but was just hoping I was missing something. I think for what I’m doing, sending it out to a scripting language is overkill. Too bad.

Drew

Hello Dave,

I’ve achieved this ‘the clumsy way’ by adding 26 replacements (one for each letter of the alphabet):

Replacement expression:

Apt. $1A (B, C, D ...)

It works for me.

Hans

I had the same issue as in this thread, but as it happens I have BBEdit, and the regex engine in BBEdit (viz. PCRE) does support case modification in replace. So I’m using an Apply BBEdit Text Factory and doing a grep replace in a BBEdit text factory. It seems to work fine for me so far.

John