Search and Replace string between markers using regex multiline

I'm afraid I've been here before, and I've read about 15 other posts on almost exactly the same topic, but after about 45 minutes, I'm really stuck again.

In this text example, I'm simply trying to remove all of the strings that begin and end with { }
So for example: 1. e4 c5 2. Nf3 Nc6 { B30 Sicilian Defense: Old Sicilian } 3. d3 g6 4. g3 Bg7 5. Bg2 e5

Would remove:
{ B30 Sicilian Defense: Old Sicilian }

My regex has included the space after the { and before the }, but I've also tried it without. I've tried the action as a straight up search and replace without the each line component also.

Any help appreciated.

Keyboard Maestro Actions.kmactions (3.1 KB)

You are very close. The curly brackets "{ }" are RegEx metacharacters, and must be escaped to use as normal characters.

Use this:
\{.+\}

1 Like

Ah yes. Regex101.com works without the escaped { characters. I see from the KM Wiki that {} form part of many other regex metacharacters (if that's the right usage). Every day is a school day, Many thanks as always @JMichaelTX.

1 Like

That is surprising. IMO it should not have worked at Regex101.com.
However they use PCRE (Perl Compatible Regular Expression) engine, whereas KM uses the ICU engine. They are very similar, but occasionally there is a difference.

It appears that it depends on the RegEx engine.
My approach is to always escape metacharacters, because that will always work with all of the engines.

1 Like