Searching for non-consecutive text

Joined
Aug 7, 2022
Messages
3
Reaction score
0
I need to search a document for every instance that two or more words appear in the same sentence or paragraph, though the words will not necessarily be consecutive. There will be other words between them. Is this possible?
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
580
Reaction score
50
You could use a wildcard Find, where:
Find = (<[! ]@>)[!.]@\1
The result will highlight strings beginning & ending with the same word within a sentence. Do note that the Find won't work with strings that include abbreviations containing periods .
 
Joined
Aug 7, 2022
Messages
3
Reaction score
0
You could use a wildcard Find, where:
Find = (<[! ]@>)[!.]@\1
The result will highlight strings beginning & ending with the same word within a sentence. Do note that the Find won't work with strings that include abbreviations containing periods .
Thank you, but the code you have posted is a bit over my head. The two terms I want to find are 'jump' and 'run'. Could you please show me how to construct the code to find those two words?
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
580
Reaction score
50
My bad. I interpreted your post to mean the same word appeared more than once in a sentence. To find instances where a given two words occur, you would need two wildcard Finds, where:
Find = <word1>[!.]@<word2>
and:
Find = <word2>[!.]@<word1>
To find instances where a given three words occur, you would need six wildcard Finds, where:
Find = <word1>[!.]@<word2>[!.]@<word3>
and:
Find = <word1>[!.]@<word3>[!.]@<word2>
and:
Find = <word2>[!.]@<word1>[!.]@<word3>
and:
Find = <word2>[!.]@<word3>[!.]@<word1>
and:
Find = <word3>[!.]@<word1>[!.]@<word2>
and:
Find = <word3>[!.]@<word2>[!.]@<word1>
and so on. Obviously, if it could be any two of the 3 words, another six wildcard Finds would be needed.
The result will highlight strings beginning & ending with the first & last specified words within a sentence. Do note that the Find won't work with strings that include abbreviations containing periods.

A macro could be used to automate the matching for any number of words in any order but, as you can see from just the examples above, the complexity rapidly increases as you add more words.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top