RegEx - Find and Replace with Variables

I am trying to figure out how to convert a simple Keyboard Maestro (KM) text manipulation workflow into Drafts action. Please note that I don’t know Java Script but perhaps with some examples, I can figure out the basics principles of RegEx Find & Replace in Javascript.

A plain text document contains an instance of “Mr. John Smith” (name varies) The rest of the document refers to the client as Mr. XX. My KM workflow copies text to clipboard and then runs the RegEx with variables.

/([M][r-s]\.\s)(\w*\s)(\w*)/g;

Where:

Group 1 = Mr.
Group 2 = John
Group 3 = Smith

Group 2 is set to variable FirstName
Group 3 is set to variable LastName

I then tell KM to replace all instances of XX with LastName variable.

1 Like