0
votes

I want to search strings like "number 1" or "number 152" or "number 36985". In all above strings "number " will be constant but digits will change and can have any length. I tried Search option using wildcard but it doesn't seem to work. basic regEx operators like + seem to not work. I tried 'number*[1-9]*' and 'number*[1-9]+' but no luck. This regular expression only selects upto one digit. e.g. If the string is 'number 12345' it only matches number 12345 (the part which is in bold). Does anyone know how to do this?

2

2 Answers

1
votes

Word doesn't use regular expressions in its search (Find) functionality. It has its own set of wildcard rules. These are very similar to RegEx, but not identical and not as powerful.

Using Word's wildcards, the search text below locates the examples given in the question. (Note that the semicolon separator in 1;100 may be soemthing else, depending on the list separator set in Windows (or on the Mac). My European locale uses a semicolon; the United States would use a comma, for example.

"number [0-9]{1;100}"

The 100 is an arbitrary number I chose for the maximum number of repeats of the search term just before it. Depending on how long you expect a number to be, this can be much smaller...

The logic of the search text is: number is a literal; the valid range of characters following the literal are 0 through 9; there may be one to one hundred of these characters - anything in that range is a match.

The only way RegEx can be used in Word is to extract a string and run the search on the string. But this dissociates the string from the document, meaning Word-specific content (formatting, fields, etc.) will be lost.

0
votes

Try putting < and > on the ends of your search string to indicate the beginning and ending of the desired strings. This works for me: '<number [1-9]*>'. So does '<number [1-9]@>' which is probably what you want. Note that in Word wildcards the @ is used where + is used in other RegEx systems.