Reputation: 113
for example, I have to search for "2/2" and I get these results:
2/2 good result
11/2/2022 bad result
when I use Advance search in MS -word the "find the whole word" is disabled because my search contains special characters. also, I tried wildcard search but I didn't know how to construct a good search string for that is there a way to find an exact match for non-word search?
Upvotes: 1
Views: 557
Reputation: 13515
You could use wildcards, with:
.Text = "<2/2>"
With this expression, the < and > specify a word start & end, respectively.
Event that, however, is prone to false matches with strings like 2/2/2022, since the / after the 2/2 designates a word end. Clearly, your code would need some additional checking to check whether a given match is valid. Such checking might be done via a Find expression like:
.Text = "[!/0-9A-Za-z]2/2[!/0-9A-Za-z]"
This tells Word to find 2/2 only when the preceding and following characters are not a /, a number, or a letter. Then, to manipulate the found text, you'd simply move the start of the found range forward one character and the end of the found range back one character.
Upvotes: 1