PDA

View Full Version : Search with regular expression



flea333
07-31-2012, 10:59 PM
Hi, I want to do something seemingly simple with reg expressions in the Word Find box: search for two words in a single line separated by any set of characters, except of course a new line character.

I've tried several syntax's that do not work.

So for example, I want to find any single line of text (isolated by carriage return/new line character) containing the two words "cat" and "mouse" I tried:

^l*"cat"*[~^l]"mouse"*^l

Problem is that returns the maximum amount of characters before seeing a new line. So I tried # etc but couldn't find it. Basically if I just figure out how to specify all characters except a new line I should be able to get my two words and that expression with the correct result.

eg: cat[expression of characters not inclusive of new line]mouse

This should return result:

The cat chased after the mouse.

But not:

The dog chased after the cat.
Then chased after the mouse.

macropod
08-01-2012, 05:15 AM
Hi flea,

Try: cat[!^l^13]@mouse

flea333
08-01-2012, 12:45 PM
Thanks macropod...however it looks like i had to remove the ^l to make it work fully.

Also I ran into a snag where it would reset the find at the top of the document and get "stuck" there. So I had to delete both the title page and the TOC in order to get the search to actually go through the main document again with a new search term upon completing a search.

macropod
08-01-2012, 03:18 PM
The '^l' was there only because you specifically referred to "carriage return/new line character". The '^l' represents a manual line break (ie new line).

As for "it would reset the find at the top of the document and get "stuck" there" I don't know what the 'it' is that got stuck but, if it's vba code, perhaps you're using the wrong range designation and/or wrap property. Since you haven't posted any code, I can't really say.