Is there a way to search for “zero or more occurrences” with MS Word wildcards?
Not *, which searches for zero or more of any character, but zero or more occurrences of a specified set of characters.
For example, suppose I wanted to find any of the following strings:
“cat dog”
“catdog”
“cat dog”
but not
“cat.dog”
Word does not want to let me use “cat{0,}dog”–if I change the “number of occurrences” to {1,} it works just fine.
Also, how would I have Word search for a pattern an unlimited number of times? Let’s say I wanted to find strings like:
fat rat rat
fat rat rat rat fat rat rat
but not plain old
fat rat
I feel like I should be able to enclose the whole find expression in parentheses and then apply the “number of occurrences” after the parentheses
((fat ){1,}(rat ){2,}){1,}
I am not sure you can do it in Word. However, there are lots of powerful text editors usually used for computer programming and text file manipulation that can do that sort of thing. Is that something you would be interested in?
Unfortunately, no. The files I’ll be working on are in Microsoft Word format, and I’m writing a macro for coworkers who are all using Microsoft Word and not likely to switch to a different text editor.
I must not be understanding what the term “zero or more” means. It seems to me that every document ever written has either zero occurences of a particular text string, or more than zero. Therefore, as I understand the logic, any search for zero or more would always return positive results.
Well, what I was looking at was an optional occurrence of a certain phrase in the context of another phrase.
If abc, abbc, and ac are all phrases that I want to search for, but the only letter that can go between “a” and “c” is “b,” I want to specify:
search for a
search for zero or more occurrences of the letter b
search for c
I am not literally searching for the phrase “fat rat”–the macro will take input from a table.
Reply–thanks for the link–from looking at the page it seems like extra support needs to be installed to use regular expressions. Does this mean every user of the macro would also have to install that support in order to use the macro?
On my machine, I did have to reference to the RegExp thing, but it was actually already installed. Maybe it’s a part of the standard Office (2003) install now? I’m not sure. I don’t know if it’s present on every machine, but it might be worth your while to find out for sure…