[SOLVED] Search for Colon and Put a Forward Delete in Front of It

Hi,

I often need to put a forward delete in front of a colon, to bring the below line up to meet it. For example-

Profile ID:
31340425
Account ID:
2370730

convert to this

Profile ID: 31340425
Account ID: 2370730

I cannot seem to figure this out with search and replace.

Screen Shot 2022-11-01 at 7.53.10 AM

This does not work...

Try this instead:

:%LineFeed%
:%Space%

(Looks for colon followed by line feed and replaces with colon followed by a space - to match the example you showed.)

1 Like

And why would you think it would? There is no text token for forward delete – forward delete is an action not a token.

Tokens [Keyboard Maestro Wiki]

@Zabobon is on the right track, but in my experience it's really common for something like this:

Profile ID:
31340425

To actually be:

Profile ID:<one or more whitespace characters>
31340425

So I tend to use a regular expression instead of literal text replacement:

Search:

(?m)(?<=:)\h*$\R(?=\d+)

Replace:

%Space%

Depending upon the task I frequently preprocess the data to remove trailing whitespace characters, non-breaking-spaces, and other issues.

This practice has saved me more than a few headaches.

When pulling data from unknown sources you also have to watch out for unusual invisible characters – those can really get you chasing your tail trying to figure out why your search/replace patterns aren't working...

4 Likes

Sage advise from a Sage.

1 Like

Thanks, ccstone and @kcwhat

Forgive me, I'm no coder. I use KM to overcome RSI from typing and mousing. KM really saved my career. Anyways...

Here is what I tried, following your advice (probably incorrectly).

Screen Shot 2022-11-02 at 9.47.16 AM

and

Screen Shot 2022-11-02 at 9.45.53 AM

Thanks for taking the time to help an ignorant stranger!!!

@Ihventura_Hutch -

Change your Search for area to Regular Expression (ignoring case). @ccstone Indicated this in his suggestion.

KC

1 Like

@kcwhat @ccstone Thanks, friends. I'll give this a shot!

@Ihventura_Hutch - No problem. It should work for you. When you confirm it, please mark @ccstone’s post as the solution.

Take care,

KC

Wooot! That works perfectly. This really saves me a lot of time. I am so grateful! Thanks, @ccstone !!

1 Like