Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

AND and OR in Find and Replace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kuku1375 - 26 Nov 2005 23:27 GMT
Is it possible to use operators like AND or OR in Word's Find and Search,
e.g. to find all instances of "John Smith" and "J. Smith" in one search?
Jezebel - 27 Nov 2005 00:44 GMT
If you check the 'Use wildcards' checkbox, the find and replace mechansim is
a version of Regular Expressions, which you will find documented in numerous
places on the net. (For no obvious reason, Microsoft doesn't quite follow
the standard, but close enough for most purposes.)

Regular expressions don't use AND or OR as such, but they do provide
equivalent mechanisms: eg, [xyz] means 'x' or 'y' or 'z'; [0-9] means any
single digit. For your example, searching for:  J[! ]{1,} Smith   will match
"J plus one or more non-space characters plus space plus Smith". IE, both of
your examples plus any number of variants like "Josephine-Keller Smith" etc.
Note that it doesn't match "J Smith". (One of the unfortunate gaps in MS's
regular expressions is 'Zero or more'.)

You could also use J*Smith which matches "J plus zero or more characters
plus Smith" which might be acceptable depending on your source data; but it
would also match strings like "John Brown and Michael Smith".

> Is it possible to use operators like AND or OR in Word's Find and Search,
> e.g. to find all instances of "John Smith" and "J. Smith" in one search?
kuku1375 - 27 Nov 2005 02:17 GMT
Thank you! I read Help before, but their language of "One of the specified
characters
Type [ ] " was not quite clear for me. I wish they used Regular Expressions!

> If you check the 'Use wildcards' checkbox, the find and replace mechansim is
> a version of Regular Expressions, which you will find documented in numerous
[quoted text clipped - 15 lines]
> > Is it possible to use operators like AND or OR in Word's Find and Search,
> > e.g. to find all instances of "John Smith" and "J. Smith" in one search?
Graham Mayor - 27 Nov 2005 07:32 GMT
Maybe http://www.gmayor.com/replace_using_wildcards.htm  will help?

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thank you! I read Help before, but their language of "One of the
> specified characters
[quoted text clipped - 24 lines]
>>> Search, e.g. to find all instances of "John Smith" and "J. Smith"
>>> in one search?
Greg Maxey - 27 Nov 2005 03:55 GMT
Offered only as a novelty:

Another user and I where discussing using OR in a find text problem.  The
discussion turned to a very real human situation where the house is locked
and the car is locked.  A known spare house key is in the car and a known
spare car hey is in the house.  There are other keys somewhere to be found.
Obviously the problem is resolved and the search can end when either a house
or car key is found.

Cheers

Sub HelmutsDilemma()
Dim aWord As Range
Dim myStr As String
For Each aWord In ActiveDocument.Range.Words
 myStr = aWord
 If InStrRev(myStr, " ") = Len(myStr) Then
   myStr = Left(myStr, (Len(myStr) - 1))
 End If
 Select Case myStr
   Case Is = "car", "house"
     If aWord.Next(Unit:=wdWord, Count:=1) = "keys " Or _
       aWord.Next(Unit:=wdWord, Count:=1) = "keys" Then
       With aWord
         .MoveEnd Unit:=wdWord, Count:=1
         .Select
       End With
       Exit Sub
     End If
   Case Else
     'Do Nothing
 End Select
Next
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> If you check the 'Use wildcards' checkbox, the find and replace
> mechansim is a version of Regular Expressions, which you will find
[quoted text clipped - 17 lines]
>> Search, e.g. to find all instances of "John Smith" and "J. Smith" in
>> one search?
kuku1375 - 27 Nov 2005 15:18 GMT
Thank you all for the valuable information you shared. However there is
another problem related with search using wildcards. I tried an example from
Help i.e. 10{1,3} to find "10", "100", and "1000" which worked fine. However
a friend got a problem - see the skrinshot:
http://img513.imageshack.us/my.php?image=err0gs.jpg
What causes the error?

> Offered only as a novelty:
>
[quoted text clipped - 52 lines]
> >> Search, e.g. to find all instances of "John Smith" and "J. Smith" in
> >> one search?
kuku1375 - 27 Nov 2005 20:07 GMT
I found the cause of the error. Regional settings were not English, so the
formula had to use semicolon rather than comma.

> Thank you all for the valuable information you shared. However there is
> another problem related with search using wildcards. I tried an example from
[quoted text clipped - 59 lines]
> > >> Search, e.g. to find all instances of "John Smith" and "J. Smith" in
> > >> one search?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.