Regex to capture and replace in-line

I've been using basic string triggers with regex to replace text as I type. E.g. \bign\s into ing[space] using the "insert text" action. This works for words with the "ing" suffix but incorrectly modifies something like "foreign".

I can't do anything more sophisticated like converting \b.?[^e]ign\s into \b.?[^e]ing\s since the "insert text" action doesn't work with captured groups from the triggered regex. I understood that you can use the clipboard to do this but I could use a hand.

If someone has already written a similar macro that does this sort of in-line search and replace, could you share?

It can.

You can use the TriggerValue token to get the captured text, and then adjust your behaviour based on this.

But better is to use a negative look behind assertion, (?<! ...)

(?<!e)ign\s

this will match “ign\s”, but only if the previous character is not an e, that previous character is not included in the match.

3 Likes

Thank you, Peter. The regex you proposed worked perfectly and I'll experiment with "TriggerValue" for some other cases.

1 Like