Does KM Support Two-Digit Regex Back References?

If so, what is the notation?

Oh, I see that the $ notation works for two digits, but not the \ notation. The wiki suggests otherwise.

This used to be a common problem.

The backslash is an escape character and doesn't tend to work with multiple characters, unless they are specially annotated like \x{00A0} – Unicode for non-breaking-space.

So \10 is actually back-reference 1 with a literal 0 after it.

I seem to remember that there was a tricky way of forcing the multi-digit reference, but I can't quite remember the syntax.

This may or may not be the problem with Keyboard Maestro, but either method of denoting a back-reference should just work.


How about \g{n} ?

Just a guess...

That's proper for regex in general, but I didn't actually test it in KM, because I stopped messing with it when I got the $ notation to work. Thanks, though.

It doesn't work with Keyboard Maestro or PCRE.

Offhand I don't see any references to \g{n} outside of PHP – if you know of any more please do me a favor and list them.


Since I got the $ notation to work, I haven't tested anything else, but the fact that it works suggests that the $ notation automatically expects either one or two digits. This, in turn, suggests that if you want to, say, match the third back reference followed by the literal, 4, then \34 would work, but $34 would fail (because it refers to back reference 34). I assume that $3\4 would also fail, because that seems to refer to back reference 3 followed by back reference 4. Of course, $3[4] could work. Whatever the case, this should be clarified in the wiki.

For regex, you can use:

  • $23
  • ${23}
  • ${2}3 - disambiguate $23 and the sequence $2, 3.
  • ${name} - named capture groups
  • \2 - only a single digit, so 0-9 only.

I have clarified the documentation.

1 Like