Exclusively Matching a Particular Set of Phrases


I'm struggling to come up with 1 or more regular expression(s) that would match a set of words and at the same time not match another set of similar words. Greatly appreciate any help.

Match these:
License Type
License Status
Licensing Authority

Do not match these:
License Degree
Licensing Body
License SubType
Best State License?
License Certification
License Status Condition
Address from License Source


Difficult to say without seeing the text you are looking in and, importantly, what you want to happen when there is/isn't a match.

But if each of your samples is a complete line of text it would easier to use an "If... any of the following..." and list your five matches, each as a "The text... is" condition. But if you want a regex (which would make the action shorter!) then "matches ^(License|License Type|License Status|Licensing Authority)$ will do the trick (and is easy to understand/maintain).

Hey Chris,

Is this an actual use-case?

If not then please post one.


Hi @Nige_S and @ccstone, thanks for responding. My original post was a simplified version of the actual real case. But here is the actual use case.

There is an internal webpage that displays all License type fields. All the fields are displayed on the page but not all fields are used. Based on what fields/values being submitted will determine which License type will be created.


License Type 1 requires these fields:

  • License Authority
  • License
  • Prescriptive Authority
  • Sample Eligibility
  • License Type
  • License Status
  • License Expiry

License Type 2 requires these fields:

  • License Authority
  • License
  • License Type
  • Drug Schedule Details
  • Address
  • License Status
  • License Expiry

So, if I were to create License Type 1, I would like only those fields to be highlighted on the webpage. This is a visual guide to help me remember which fields I need to populate.

As for highlighting words/phrases on webpages, I use a Chrome extension HighLight This! - it automatically finds and highlights words and phrases on the web pages according to your predefined list. It also supports regular expressions.

Warning: This extension used to be really good. But recent updates have shown that it is redirecting traffic to some websites through affiliate links.
Highlight This!

But since I cannot get the highlight working properly with RegEx, I resorted to this work around. I have a macro for each License Type that just "Clicks at found image, with Display checked" for all the required fields.



I fear that your problem will be with the License string -- the plug-in has the concept of RegEx "anchors", but I'm not sure how they'd apply in web page text.

Try ^License$ and see what gets highlighted. If it's only the top-right field in the picture then you can just list the matches as I did earlier. It's a clunky method, but it is an easy one!

Hey Chris,

This is one of those cases where the devil is in the details – without knowing the exact nature of this task any speculation toward a solution is next to worthless...

Put your eyeballs on post #4 of this topic and run the following macro.

Highlight DOM Elements on a Web Page v1.00.kmmacros (6.0 KB)

Macro Image

Keyboard Maestro Export

I'm not especially happy with this code, but my Js-Fu is not strong enough to do much better at the moment.

In any case – it demonstrates a bit of what's possible.

Personally I think I'd be looking for a way to auto-fill this page as much as possible, but without being able to dissect and tinker with the live code...


@Nige_S, when I use ^License$ it does not highlight anything. When I use License all occurrences of the word License is highlighted.

@ccstone, I appreciate you creating the macro. I'm not familiar with javascript, so not sure what to do.

I think this is one of those times when it's easier to just use the work-around. But thank you both for taking the time to help. :slight_smile:


Did you run the macro per the given instructions?

@ccstone, yes I ran the macro but nothing happens. Am I supposed to replace #post_4 with something else? Sorry, I'm not familiar with javascript.

You must not have enabled the imported macro, or you're not looking in the right place...

The JavaScript is doing the highlighting of your own post #4 of this topic.

What I'd try is to throw a prompt asking "License 1 or 2?" and then throw another containing only the appropriate fields -- fill those in and have KM do the form entry.

Then you'll only see what you need -- and you'll always need what you see!

Hi @ccstone, yes I noticed the macro highlights my #4 post of this topic. However, I do not know how to modify the script to highlight the specific License fields of the internal webpage. I'm not that familiar with JavaScript.

Hi @Nige_S, that's a good suggestion. But right now, I'm satisfied with the work around. Thanks though.

Yet you said:

The fact you know nothing about JavaScript is beside the point here.

Nevertheless – I'm glad you found a solution that will work for you.

Just to clarify, I meant nothing happened when I ran the macro on the internal webpage. So, I suspected I needed to make modifications to the JavaScript which I'm not familiar with.