Find and Replace using wildcardsThis tutorial pre-supposes that the user will have somebasic experience of Word's 'replace' function.The secret of using wildcard searches is to identify theunique string of text that you wish to find. Wildcards arecombined with regular text and formatting options torepresent the characters or sequences of characters inthat string. Because different combinations of characterscan be represented by a variety of wildcard combinations,there is often more than one way of identifying a particularstring of text within a document. How you choose torepresent that group of characters is therefore a matter ofindividual preference; and the context of the text within thedocument will to a great extent dictate the most suitablecombination to use on a particular occasion.Start by identifying the string you wish to replace and thenpop up the replace function (CTRL+H) or select AdvancedFind from the Editing group on the Home tab of theribbon (see below); or in earlier Word versions Edit >Replace.Click the 'More' button to present the additional functions and check the 'Use wildcards' option:Insert your find and replace strings using the following guide for inspiration.You can paste any (Unicode) character - unfortunately*not* characters from decorative (Symbol) fonts) - into your search expressions. So copying the first and last characters from the Greek or cyrillic subsets into a search:[;-ώ] would match any Greek character α β γ δ ε...<[Ё-ґ]@> matches any cyrillic word: Вы можете помочь мне?(“Can you help me please?”)In Word 2000, you can type in Unicode characters with the Alt-key (make sure NumLock is on, then hold down the Alt-key and type the numbers on the numeric keyboard). Since all characters from decorative fonts (Symbol-, Wingdings-fonts ...) are kept in a special code page from &HF000 to &HF0FF, you can search for them with[Alt61472-Alt61695].Gotchas <![endif]>.You may wish to identify a character string by means of aparagraph mark ¶. The normal search string for this wouldbe ^p.^p DOES NOT WORK in wildcard search strings! It musthowever be used in replacement strings, but whensearching, you must look for the substitute code ^13.Wildcard searches will also not find footnote/endnotemarks - substitute ^2.A-z would be expected to reproduce all the letters betweenA and z i.e. both upper case and lower case letters, whichit does, but it reproduces all the characters from ASCII 65to ASCII 122, and that block also includes the characters [ ]` ^ _ / Use A-Za-z instead.The question mark ? is used to find individual characters.If used with curly brackets to define a range of characterseg#?{1,3}# it will behave as an asterisk and find all thecharacters between the hash symbols.Control Codes that may be used with the search/replace tool/?kbid=197855Graphic (In Line Graphics Only). In Word 2007 a forward slash / also appears to find in-line graphics. This appears to be an unintentional bug.New line -Tab -Paragraph Mark -There are many occasions when you are presented with blocks of text or numbers etc., where the order of the textis not what you might require in the final document. Swapping the placement of forename and surname as above is one such example - and don't forget you can add to the replacement, even when using bracketed replacementse.g. you may wish John Smith to appear as Smith, John or, more likely, you may have a column of names in a table, where you wish to exchange all the surnames with all the forenames.You could do them one at a time, but by replacing the names with wildcards, you can do the lot in one pass.Let's then break up the names into logical sequences that can only represent the names.At its simplest, we have here two words - John and Smith.They can be represented by <*>[space]<*> - where[space] is a single press of the spacebar.Add the round brackets (<*>)[space](<*>) and replacewith \2[space]\1Run the search on the column of names and all areswapped. Run it again and they are swapped back.Example 2This could be the changing of UK format dates to USformat dates - or vice versa.7th August 2001 to August 7th, 2001To give an example of how most of the wildcards could beused in one search sequence to find any UK dateformatted above to its equivalent US format date, thefollowing search pattern will do the trick:[0-9]{1,2}[dhnrst]{2} <[AFJMNSOD]*>[0-9]{4}Breaking it down [0-9] looks for any single digit number,but dates can have two numbers so to restrict that to two,we use the count function. We want to find dates with 1 or2 numbers so[0-9]{1,2}Next bit is the ordinal 'th'- Ordinals will be 'st' 'rd' or 'th' so identify those lettersspecifically:[dhnrst]There will always be two letters, so restrict the count to 2[dhnrst]{2}Next comes the space. You can insert a space [space]The month always begins with one of the following capitalletters - AFJMNSOD. We don't know how many letters thismonth has so we can use the blanket '*' to represent therest. And we are only interested in that word so we will tieit down with <> brackets.<[AFJMNSOD]*>there's another space [space] followed by the year. Theyears here have four numbers so[0-9]{4}Finally add the round brackets to provide a logical breakupof the sequence([0-9]{1,2}[dhnrst]{2})[space](<[AFJMNSOD]*>)[space]([0-9]{4})and replace with\2[space]\1,[space]\3to re-order the sequence.Example 3Assume you are parsing addresses and wish to separatethe honorific from the name.American usage puts a full stop (period) at the end ("Mr.","Mrs.", "Dr.") while British usage often omits the full stop.([DM][rs]{1,2})( )will find Mr Mrs Drwithout the stop and\1.\2will put one in.or vice versa([DM][rs]{1,2}).will find Mr. Mrs. Dr. with the stop and\1will take it out.Further examples:(*^13)\1\1 will match any sequence of three identicalparagraphs,(*^13)@ will match any number of replacementparagraphs. Replace with \1 to remove duplicates from asorted list.\<([!\<\>]@)\>[!\<\>]@\</\1\> will match any well-formedXML element including start-tag and end-tag(“<p>some text</p>” or “<customer-name>JohnSmith</customer-name>”)By creating logical sequences you can search for almostany combinations of characters.Gremlins to be aware of (for advanced users only)Sometimes Word will get confused if it encounters“escaped” brackets \( or \), for example “(\\)” will match*any* character, not only a backslashWorkaround: use "([" instead.([a-z]\() throws an error - should find an "a(".Workaround: Use ([a-z][\(]) instead.Not a bug but still annoying: You have to escape anyspecial character even if you type its code; so ^92 willhave the same problems as typing the backslash.The construction {0,} (find zero or more of the precedingitem) is refused as incorrect syntax. This concept isavailable in Unix regular expression matching, so it's acurious omission.You don’t always have to “escape” the special characters,if the context makes it clear that the special meaning isn’twanted. [abc-] matches "-", and [)(] matches ")"or "(". This may sometimes make your searches behavedifferently from what you expected.Establish the unicode decimal number for a characterWhen searching for a symbol from the extended characterset using its unicode decimal number i.e. ^unnnn you firstneed to identify that number.First select the first example of the character (e.g. theCyrillic character ю in the document, then activate theInsert > Symbol dialog.The dialog opens with the character selected:Note the Unicode (hex) character code number - here 044E.Open the Windows calculator and change its view to the Programmer's calculator, ensure that the Hex radio button is checked and enter the number into the calculator.Click the Dec radio button and note the changed numberYou can then use the four digit number in conjunction with the ^unnn (^u1102) to find the characters in the document.Macro to identify the four digit number indicated aboveThe following macro will identify and copy the value of thecharacter at the cursor to the clipboard, for ease of pastinginto the find and replace tool's 'Find what' dialog.If you don't know how to use macro listings, see/installing_macro.htm.Sub GetExtendedCharDecVal()Dim SelFont As VariantDim SelCharNum As LongDim myData As DataObjectDim sCode As StringSet myData = New DataObjectSelect Case Len(Selection.Range)Case Is = 0MsgBox "Nothing selected!"Exit SubCase Is = 1With SelectionWith Dialogs(wdDialogInsertSymbol)SelFont = .FontSelCharNum = .CharNumEnd WithEnd WithIf SelCharNum < 128 ThensCode = "^" & SelCharNummyData.SetText sCodemyData.PutInClipboardMsgBox "To find this character, use """ & sCode & """ in the 'find what' field." & vbCr & vbCr & _"This has been copied to the clipboard. Use Ctrl+v to paste into the 'find what' field."End IfIf SelCharNum > 127 ThensCode = "^u" & SelCharNummyData.SetText sCodemyData.PutInClipboardMsgBox "To find this character, use """ & sCode & """ in the 'find what' field." & vbCr & vbCr & _"This has been copied to the clipboard. Use Ctrl+v to paste into the 'find what' field."End IfCase ElseMsgBox "Select only the character to evaluate, and run the macro again"Exit Sub End Select End Sub。