How To Count Instances of a Certain Word

I’m trying to count the instances of a certain word on a webpage. What I’d like to do is close any tab with more than two instances of that word, so I THINK I need to:

  1. copy the contents of the page into a named clipboard
  2. search the content of that named clipboard for WORD
  3. set variable wordCount to the number of instances
  4. IF: wordCount >2, close tab.

The problem is, I don’t know how to accomplish steps 2 and 3. :blush: How can I accomplish this?

Thanks!

This should count the instances of the word:

Count Clipboard Word Instances.kmmacros (3.0 KB)

Thank you, this works great. Is there a source you’d recommend to learn some of basics of regular expressions? I’d like to be able to tinker with it next time before running to the forums.

Thanks again!

Open(can(worms)) :slight_smile:

For testing expression syntax, I'd recommend regex101.com. As for learning, well.. see this thread:

1 Like

Thank you. It is very interesting so far. http://regexr.com/ has been useful for kluding my way through the simple things I want to do so far :slight_smile: Bookmarking your post for future reference.

Good you you for sticking with it! I found that when I started using regex’s whenever possible, I learned more quickly. So I use them in various editors to find things. Helps a lot.

:slight_smile:

Yes, I never knew it was possible to search for patterns and went to bed thinking of ways I could apply it to other tasks.

2 Likes