Browse the docs

Clipboard matches

Passes when the clipboard text matches a regular expression.

The clipboard matches regex

Keyboard Maestro: Text (clipboard matches)

Details #

Reads the text on the clipboard and searches it for regex. The match can be anywhere in the text; anchor with ^ and $ to match the whole thing. Matching is case sensitive. A clipboard with no text counts as empty text.

Every condition accepts "negate": true, which flips the verdict. The trace records what was compared before the flip, so a negated condition that blocks a macro still shows the real values.

Conditions in an Only if list combine with all: every one must pass, and an empty list always passes. An if step or a repeat loop takes a match of all (default) or any.

The trace shows clipboard (the first 200 characters) and regex.

Parameters #

ParameterTypeRequiredValuesWhat it does
regextextYesA regular expression. Escape backslashes in JSON: \\d+ for digits.

Examples #

Only when the clipboard is a URL
When
  1. Press ⌃⌥J
Only if
  1. If the clipboard matches “^https?://”
Do
  1. Show “Clipboard holds a link”
Open in Switchboard to try it
Only when the clipboard has no digits
When
  1. Press ⌃⌥J
Only if
  1. If the clipboard doesn't match “\d”
Do
  1. Show “No digits copied”
Open in Switchboard to try it

Gotchas #

  • An invalid regular expression makes the condition error rather than fail.

See also #