Find Specific Text in Clipboard and Set To Variable

Here is what I am trying to do:

  1. Find text using regualr expression “Date of Birth: October 1, 1985”
  2. Set the Vriable DOB to “October 1, 1985”

How can I go about doing this so that I find “Date of Birth:” but not include the actual words in the variable?

I need this workflow to search the content of a text file and get all the right variables such as date of birth, date of loss, and the date of date of report. I will then switch to Pages and use Find and Replace to repalce DOB, DOL, and DOR with proper variables.

I think I figure it out. I used Clipbaord Search Regular Expression and Set to Variable.

Date of Birth: (\w* \d, \d*)

The moment I entered "(\w* \d, \d*)" KM magiacally gave me a menu to set a group 1 variable to Find Results.

Is this the best way to go about this?

Keyboard Maestro 8.0.4 “Find and Replace Clinet Info” Macro

Find and Replace Clinet Info.kmmacros (4.7 KB)

If the dates of birth and loss are always in the exact format Month Day, Year then what you’ve come up with should generally work, with one major exception: using \d for Day will only match single digit days, and cause the action to fail for days with two digits. Fortunately, this is an easy fix. Again, assuming that dates are always going to be in this exact format, here’s how I would write the regex:

Date of Birth: (\w+ \d{1,2}, \d{4})

(I’ve used “Date of Birth” as the example here, but the same exact regex should also work for “Date of Loss”)


Thank you! Your suggestion also fixed my other probelm - Bring Application Window To Front Not Working

1 Like