For an exact match search, enclose multiple words in double quotes

When I search on various website such Google, Twitter, etc., I often use exact match search.
That is, surround the word with double quotes.

Example
test apple orange-juice

"test" "apple" "orange-juice"

I would like to create some macro with a KM shortcut to avoid having to manually add double quotes to multiple words.
After doing some research myself, I think maybe I should use regular expressions, but I can't understand how to write them specifically...

My new macro would help do that in a single action.

1 Like

Here's your regular expression:

(\S+)

  • The parens define a capture group, which is referred to in the replacement string (below) as $1
  • \S (the "S" is upper case) means to match any non-whitespace character
  • + means match one or more of the \S characters

Here's your replacement string, complete with the quotes:

"$1"

The result:

"test" "apple" "orange-juice"

image

3 Likes

You don't need a regular expression. @DanThomas's is very neat, and well explained, but sometimes it's easier to use something that's less efficient but that you already understand. In this case you just want to replace every space with quote-space-quote

test apple orange-juice -> test" "apple" "orange-juice

...then add an extra " front and back

test" "apple" "orange-juice -> "test" "apple" "orange-juice"

3 Likes

Thank you very much Dan Thomas, I did it with this macro.


Other respondents have come up with different idea, so I'll try it too.

Thank you very much Nige_S, I tried @DanThomas 's idea, and succeed, but I want to understand your idea too.
So I made this macro, but It doesn't work.

Surely I must have misunderstood something, because I have no idea what Local My Search means.
Would your idea allow me to avoid having to copy and paste the words?
For original purpose, there's no need to store it in the system clipboard, so it would be great if I could just replace it directly in the search input field.
Thank you very much.

Sorry, I should have said. I put the changed text into the variable Local_mySearch rather than changing the contents of the clipboard -- which you may or may not want to happen. In this case you do because you are using copy and paste to change the search field.

1 Like

Using the macro I provided above, here's another solution:

image

1 Like