Regex working in tester, not KM (substitution, changing order of words)

Hi all,

This is a bit of a continuation from the last query I posted. I use KM to copy data from a pdf document to dedicated book indexing software. I use a macro to invert names from "first name last name" to "last name, first name". I've been working on modifying my name inversion macro to behave well with hyphenated surnames.

The RegEx I have to do this seems correct in the tester, but isn't performing in KM. I assume there's some setting or something I need to change to the expression, but even searching the history of the forums can't figure it out.

So the regex is here: regex101: build, test, and debug regex

And attaching the image of the macro and the file.

Thank you very much, I really appreciate any attempts at help.

InvertName.kmmacros (5.2 KB)

I don’t know for sure but I suspect your using Latin is incorrect. Have a look at this page in the ICU documentation for Unicode sets: and also Properties - ICU Documentation

My impression is that none of the regular expression dialects supported on that site exactly match that of the ICU regular expression engine used in Keyboard Maestro.

In what way? Have you got examples of original text, your results, and your desired results? Because a simple test shows it's working as intended:
latin regex.kmmacros (2.0 KB)

latin regex result

Sorry. I didn't meant to intentionally not offer up an example.

So, let's say my .pdf (Acrobat DC) has "John Cheney- Lippold" (not in quotes, no space in the PDF, but that's how it copied). I'm getting "Cheney- John Lippold" (no comma, and wrong inversion of names), but would like "Cheney-Lippold, John"

Your result is correct.

PDFs can be strange beasts when it comes to copying text out -- there may be an actual space that doesn't show in "display", or something else that's being interpreted as a space. You sometimes see this when what you'd consider to be a single text block has a font change and so is actually two blocks.

In this case I think you can get away with preceeding your regex action with a simple search and replace action using "- " and "-".


Oh, that was very smart, thank you. It is now behaving correctly and I'm very happy about this. I appreciate you taking the time to chime in on my various queries.

I've been using macros for about a year now in this kind of work, and I've certainly experienced what you mean about PDF copying text being a strange beast.