Need Help Creating Macro That Uses RegEx

Hello and thanks in advance for help.

I know it can be done easily with Regex but never succeeded to get around to learn it enough.

Recently I switched my email address from [myname@gmail.com] to [myname@duck.com].

I need a macro to turn a “regular” address to a “duck”...

Regular: [info.company@company.com]

For sending my email to the company, instead of the company address in the address line, I write:

[info.company_at_company.com_myname@duck.com]

So, to summarize I need to replace the 1st “@“ with “@” ; add an underscore after the 1st “.com” and paste after that”[myname@duck.com]".

Very appreciative for help.

No regex required -- you can treat the "old" address as an array, delimited by the @ symbol. I've used a variable for testing, but you could just as easily operate on the System Clipboard:

Change of Address.kmmacros (2.7 KB)

2 Likes

Thanks Nige_S
Need to go now. When back will try and update you.
In the meantime, thanks a lot!

Thanks A LOT Nige_S!!!
Exactly what I needed!!!
Tweaked it a bit (worked from the System Clipboard and some).
Have a wonderful weekend!

Hey @Saul,

@Nige_S is right – this one doesn't require a regular expression, and a solution was easily within your grasp. Plain old, ordinary string-replacement – plus knowing how variables and strings concatenate in text variable assignment actions.

Change of Address (Search & Replace String) v1.00.kmmacros (7.1 KB)

Macro Image

Keyboard Maestro Export

Mark Nige's solution well – that technique is very useful for a variety of things – and will be more so when Peter gets around to adding EOL characters to the possible delimiter strings.

Here's the regex just for fun – regex will nearly always be my go-to method for doing this sort of job, because I've used it continuously for nearly 30 years now.

Change of Address (Search & Replace RegEx) v1.00.kmmacros (6.9 KB)

Macro Image

Keyboard Maestro Export

-Chris

1 Like

Hey Chris.
As always, it's a great pleasure to get an answer from you!
Very much appreciated.
AND... of course... the macro works like a charm!!!

Regards
Saul

1 Like