< Previous Chapter | Next Chapter >

305 Chapter 11. Find & Replace

In this chapter, you’ll learn…

Every time someone asks me what’s so great about Nisus Writer and I start to tell them about its incredible Find/Replace capability, I get this oddly blank look. Find…Replace…O.K.…so? All word processors, and most other kinds of programs—even the Finder—allow you to search for some literal string of text. Everybody knows this. So anyone (namely me) who gets excited about Find and Replace is clearly off his rocker. Ah, but perhaps I’ve a shred of sanity left after all. After all, we’re not talking about just any Find and Replace. Saying PowerFind Pro is “just Find and Replace” is like saying the Batmobile is “just a car.” Sure it is—but with more gadgets and horsepower than you ever thought 306 you’d need! When you start to use Nisus Writer’s Find/Replace for the first time, you’ll begin to feel the way you did the first time you surfed the World Wide Web. “You mean it has that too?” You betcha.

Here are some samples of what you’ll be able to do. Find any address (no matter what the address is). Find any capitalized word that comes at the end of a sentence. Replace each word in ALL CAPS with a lowercase version, except those that come at the beginning of a line. Find any sequence of a name, a date, and a telephone number, and replace it with the same elements in a different order. Once you start to think about the possibilities, all kinds of indispensable uses start to turn up. Nisus Writer’s Find/Replace is just what you need to reformat complex documents, fix stupid mistakes, and in general, save yourself hours of work.

The Find/Replace functionality of Nisus Writer got a large number of much-needed improvements in versions 5.0 and 5.1. While essentially everything in this chapter is still correct, a number of limitations were removed, and many interface improvements were made.

Getting Started with Find and Replace

The first thing you should realize about Find and Replace in Nisus Writer is that a single modeless dialog box (see Figure 11.1) handles both activities. In many word processors, there’s one command for Find and another for Replace (which is actually Find and Replace, of course). This has always struck me as a bit odd—if you can use a Find-and-Replace dialog box to do both activities, why make them separate? Apparently Nisus Software agrees with this line of reasoning, and gives you just one dialog box for both activities. That’s why I talk about Find/Replace as if it’s one activity, even though you can certainly find something without replacing anything!

Figure 11.1. The Find/Replace dialog box.

Because the Find/Replace dialog box is non-modal, you can have it open all the time without it interfering with your other windows, and you can still use most of your menu and editing commands when the Find/Replace dialog box is active (i.e., in the front).

The second thing you should know is that unlike other word processors, Nisus Writer offers three different methods, or modes, of Find/Replace—Normal Find, PowerFind, and PowerFind Pro. You might think of these as the Beginner, Advanced, and Way Advanced methods—each level adds more power, and also more complexity. Since you can per-307form an ordinary, run-of-the-mill Find/Replace in PowerFind mode, I don’t think there’s any particular reason to use Normal Find at all, so I won’t say much about it. We’ll concentrate on PowerFind and PowerFind Pro in this chapter—but first, let’s look at what these terms really mean.

Understanding the Find Modes

Nisus Writer’s three find modes form a hierarchy: each level includes all the capabilities of the previous one, and then some. Which mode you use will depend on the level of complexity in your search (more on choosing a mode below). You can switch from one mode to another at any time using the Find Mode pop-up menu (Figure 11.2), or you can make one of those modes the default in the Finding Preferences dialog box. Here’s what the three modes mean:

Figure 11.2. Choosing PowerFind from the Find Mode pop-up menu.

Figure 11.3.The Find/Replace dialog box in Normal Find mode.

Figure 11.4. The Find/Replace dialog box in PowerFind mode.

One of the great improvements in Find/Replace is that PowerFind mode now has all the capabilities of PowerFind Pro (like user-defined wild cards, a “NOT” operator, extra matches, and so on—all in the familiar “bubble” presentation. Furthermore, you can now convert any expression from PowerFind Pro to PowerFind (previously, it was one way only, in the other direction).

Figure 11.5. The Find/Replace dialog box in PowerFind Pro mode.

If you switch from PowerFind mode to PowerFind Pro mode, any expression you have entered in the Find or Replace box will be converted into a PowerFind Pro expression. However, this does not work the other way around: if you switch from PowerFind Pro to PowerFind, no change will occur, and any metacharacters will be treated as literal text.

Choosing a Find Mode

Which mode should you use? Well, it depends. Normal Find is used by default when Nisus Writer is installed. But as I said above, there’s no particular reason to use it since you can do a “normal” find in PowerFind mode. So for most people, I recommend setting your Find mode to PowerFind and leaving it there (don’t forget to set this as a preference as well). You won’t give up any capabilities, but you’ll have a constant reminder that other options are available to you.

There will be times you’ll want to do something that is beyond the capabilities of PowerFind and want to switch to PowerFind Pro. In particular, this will happen if you want to find anything that’s not part of a certain set of characters (there’s no “not” command in PowerFind), or if you need to define a new wild card (like “any lowercase character from g to r, except m”). However, unless you are already familiar with UNIX grep, I don’t recommend making this your default until you are very comfortable with PowerFind, because PowerFind Pro does require some changes in the way you enter even 310 normal text. Since PowerFind Pro includes all of PowerFind’s capabilities, you’ll probably switch to PowerFind Pro sooner or later.

Performing a Basic Find/Replace

Now that we know what we’re dealing with, let’s talk about the basic procedures for Find and Replace. To display the Find/Replace dialog box (Figure 11.6), choose Find/Replace… from the Tools menu. If you’re not already in PowerFind mode, choose PowerFind from the Find Method pop-up menu. To do a basic search, type whatever you’d like to find (which we’ll be referring to as the Find expression) in the Find box, and click the Find button. To do a find and replace, type something into the replace box (the Replace expression) as well. After clicking Find to highlight the found item in your text, click Replace to replace it with whatever’s in the Replace box. Or, click Replace then Find to make the replacement and then automatically find the next match. To replace all occurrences of the item in your document at once, click Replace All.

Figure 11.6. The Find/Replace dialog box.

You can move the insertion point between the Find box and the Replace box by pressing the Tab key. Tabbing to a box selects its entire contents. To clear both boxes, including any fonts, sizes, or styles you may have applied, press Tab-Delete-Tab-Delete.

311 Some of the buttons in the Find/Replace dialog box take on alternate functions when you press the Option key. When the Option key is down, Find becomes Find All. Click Find All to find all occurrences of your Find expression and select them noncontiguously. Replace then Find becomes Find in Selection when the Option key is pressed. Find in Selection will do a “Find All,” but only within the currently selected range of text. To do a “Replace All” within just the current selection, press the Option key and click In Selection (where Replace All normally is).

As with menu commands, all the options in the Find/Replace dialog box were moved up to the surface. Now there are more buttons and checkboxes, but you no longer have to press a special key to reveal certain commands.

Using Styles in a Find/Replace

Using Nisus Writer’s Find/Replace dialog box, it’s easy to search for text in a particular font, size, or style. After entering text into your Find box, select it and choose one or more commands from the Font, Size, and Style menus. You can apply any style to a Find expression that you can apply to regular text, including user-defined styles. So, for example, if you want to search for any instance of the word “fish,” but only if it’s in italics, type in fish, select it, and choose Italic from the Font menu. Then click Find. You can also apply styles to your Replace expression in the same manner. When the replacement is made, the styles you apply to the Replace expression will be used, superceding any styles that may have previously been used in the text. When you apply a font, size, or style to the text in either the Find or Replace box, the corresponding checkbox labeled Text Only will automatically uncheck itself. Re-check this box if at any time you want to use the text you’ve entered as though it had no styles applied.

You can even apply character formatting to any part of your Find or Replace expression. So if you know that the phrase “one dark night” appears several times in your document, but you want to find only the instance where “dark” is in bold, simply type one dark night into the Find box, select “dark,” and apply the style Bold. While this may not be useful very often with literal text, it is often helpful to apply styles to metacharacters (see below), allowing you to search for things like “any sequence of two boldface words, followed by an italic word.”

312 Using the “Any” Styles

You will notice on the Font menu a choice called Any Font; on the Size menu there is an Any Size command, on the Style menu one that says +Any Styles, and on the Color menu Any Color. These special styles are all applied to your Find and Replace expressions by default, and simply mean that a find (or replace) is insensitive to that particular attribute. For example, if your Find expression is in the Any Font font, a match will occur regardless of what font the text in your document is. Or, if you apply Any Size to a Replace expression, then whatever other attributes the Replace expression may have, it will not be specified for size, and so will take on the size of the surrounding text when a replacement occurs. These special styles are independent of each other, so you can easily perform a search that is sensitive to, say, style but not size.

Find/Replace Options

Options for tailoring your search appear in two places: as controls in the Find/Replace dialog box itself, and in the Find/Replace menu (Figure 11.7), which appears on your menu bar when the Find/Replace dialog box is active. Many of the controls in these two locations do exactly the same thing. Find Text Only on the Find/Replace menu has the same function as the Text Only checkbox next to the Find window. When this option is checked, Nisus Writer will search for the text and/or metacharacters in the Find box without regard for font, size, or style. When you apply any character formatting to parts of the Find box, this choice is unchecked automatically. Checking it again will cause Nisus Writer to ignore the formatting when performing a Find. Replace Text Only (on the menu) and the Text Only checkbox next to the Replace box also do the same thing. When this option is checked, then any replacements made will take on the attributes of surrounding text; fonts, sizes, or styles applied to the Replace expression directly will be ignored.

313

Figure 11.7. The Find/Replace menu (appears whenever the Find/Replace dialog box is active).

If you have a Language Kit (or Language Key extension(s)) installed, additional Find/Replace options will be available. See Chapter 13 for information on these.

The next three options on the Find/Replace menu (which are not duplicated elsewhere) determine where your Find/Replace will be performed. Choose Active File to search the currently active document only. To search all currently open files, choose All Open. To search the files that you’ve previously added to a search list, choose Search List (for details on using a search list, see Chapter 8 under “Using the Catalog”).

The Whole File menu command (which corresponds to the Whole File checkbox in the Find/Replace dialog box) determines what will happen at the end of the search. When you click Find, Nisus Writer begins searching from the current insertion point, in the direction indicated by the “Search Direction” arrow. When it reaches the bottom (or the top, if you’re searching toward the top), the search will stop unless Whole File is checked, in which case it will “wrap around” to the other end of the document and continue searching back to the insertion point. In other words, Whole File causes the search to make one full loop through the entire document.

The last three Find/Replace menu options determine how “exact” a search is. Choose Ignore Case (or check the Ignore Case checkbox in the Find/Replace dialog box) to make searches case-insensitive. When this option is checked, a Find expression like “cats” will also find strings like “Cats,” “CATS,” and “cATs”; when unchecked, only strings that match the case exactly as entered will be found. The Sounds Like option (formerly “Fuzzy Find”) allows you to search for 314 words that are phonetically similar to what you’ve typed in the Find box—handy if you don’t know the exact spelling of a word. With Sounds Like active, typing “limmazeen” in the Find box will match the word “limousine”; the Find expression “mussle” will match both “muscle” and “mussel,” as well as “muzzle.” And the Ignore Diacriticals option, when selected, will cause the search engine to ignore any diacriticals (accents, etc.) on characters either in your document or in the Find box. For instance, if you type “resume” into the Find box, you’ll match “résumé” in your document, and vice-versa.

The Sounds Like and Ignore Diacriticals options only apply to literal text typed into the Find box, not to metacharacters.

Finding Character Graphics

Amazing but true: you can actually search for character graphics (including tables, equations, and the like) using Nisus Writer’s Find/Replace. There’s just one catch: you can only search for graphics by size. So if you have multiple graphics that are exactly the same size, the Find/Replace won’t be able to distinguish them. To find a character graphic, copy it and paste it into the Find box (or use the Copy to Find [Option-Copy] command on the File menu). Make sure Text Only is unchecked in the Find/Replace dialog box, and click Find. The next character graphic of that exact size will be located and selected. If you want to search for any character graphic, regardless of size, just select the graphic you’ve pasted in and choose Any Size from the Size menu.

You can find character graphics even in “Normal Find” mode, but of course, if you’ve read the past few pages, you’re much too sophisticated to consider using Normal Find!

Finding and Replacing Autonumbers and Variables

If you need to find an autonumber (like a page number or figure number) or a variable (like the date), you can easily insert one of these in the Find box using the regular menu commands. But you may not get exactly the result you expect, because Nisus Writer represents variables in your document using special ASCII codes, and these are what the 315 Find/Replace “sees.” Because the values are not unique, you can’t search for, say, a particular table number. Table 11.1 lists the available autonumbers and variables, along with their ASCII codes, so that you can see what will be found if you search for one of these items.

Variable or Autonumber

ASCII value

Date

15

Time

16

Document Name

17

Autonumbers (including page number and everything on the Numbering submenu)

29

Character Graphics (including tables, equations, and any other EGO objects)

1

Table 11.1. ASCII values for variables and autonumbers.

Find/Replace Without the Find/Replace Dialog Box

The Tools menu has a few “hidden” commands that give you shortcuts to additional Find/Replace activities. These can save you a lot of time when you just need to do a quick search for something. When you press various combinations of modifier keys, the Find/Replace command on the Tools menu changes to one of several alternative commands. Table 11.2 lists these commands and the keys you press to access them. These commands all behave exactly as their respective buttons in the Find/Replace dialog box do, and make use of whatever is currently entered in the Find and Replace boxes. When combined with the Copy to Find and Copy to Replace commands on the Edit menu (Option-Copy and Shift-Option-Copy, respectively), you can actually perform most Find/Replace activities without ever opening the Find/Replace dialog box!

316 To get this command

Press these keys

Find Next

Shift

Find All

Option

Replace

Command

Find in Selection

Shift-Option

Replace in Selection

Command-Option

Replace then Find

Command-Shift

Replace All

Command-Shift-Option

Table 11.2. Variations on the Find/Replace command. The command shown in the left column will be displayed in place of Find/Replace on the tools menu when the key(s) in the right column are pressed.

Where Find/Replace Applies

You can perform a Find/Replace in virtually any Nisus Writer window, even including the Macro and Glossary windows, the Character Table, and the Catalog. However, there are some limitations. First, when searching your document, the footnotes/endnotes and headers/footers will be ignored by the Find/Replace. You can search in the header/footer window or the footnote/endnote window, but this must be done as a separate activity: those windows are only searched if they are the frontmost (active) open window. However, Nisus Writer always searches invisible text in your document, even if you have Invisible Text turned off on your Display Attributes menu. So if it acts like it’s found something but nothing appears to be highlighted, you might want to turn on Invisible Text to see if it found something you can’t see.

All About Metacharacters

OK, so much for a basic search. But before we move on to bigger and better things, a brief aside is in order. In both PowerFind and PowerFind Pro, special symbols are used to 317 represent wild cards, position, clipboard numbers, and so on. These symbols are known as metacharacters. (Obligatory bad pun: I never metacharacter I didn’t like.) Metacharacters allow you to match patterns of characters in your text, and they’re the building blocks of PowerFind and PowerFind Pro expressions. PowerFind metacharacters are easy to read (), and are inserted into your Find or Replace box when you choose a command from one of the Find/Replace dialog box’s menus (which I’ll be referring to simply as the “Find menus”). PowerFind Pro metacharacters, on the other hand, are constructed out of ordinary characters, like the colon (:) and the backslash (\). For example, the PowerFind Pro metacharacter for “Word Start” is \< (which does the same thing as ). When you’re in PowerFind Pro mode, choosing something from one of the Find menus will insert the PowerFind Pro metacharacter. And if you switch from PowerFind to PowerFind Pro, all your metacharacters will be converted to PowerFind Pro metacharacters (you cannot, however, turn a PowerFind Pro expression back into a PowerFind expression).

Nisus Writer version 5.1 can now convert PowerFind Pro expressions into PowerFind expressions. This is just one of many improvements to the functionality of the Find/Replace features of the new version.

The CD-ROM contains three glossary files to help you construct Find and Replace expressions. One converts PowerFind Pro expressions into their PowerFind equivalents (when possible). The second allows you to type, say, “any word” and replace it with the correct PowerFind Pro metacharacter (), and the third converts these “plain english” expressions to PowerFind metacharacters.

PowerFind: Find Almost Anything

By way of introduction to PowerFind, let’s say you’ve just completed a search for a particular phone number (like 555-1234). Now suppose that there is a phone number in your document, but you don’t know what the number is. How can you find it? Well, for starters, you know that phone numbers follow a certain pattern. In the U.S., the pattern is three digits followed by a hyphen and four more digits. So what we need to do is use PowerFind metacharacters to represent that pattern, and find anything with that general shape.

Here’s how we do it: First, with the Find/Replace dialog box open and in PowerFind mode, pull down the Wild Card menu that’s inside the Find/Replace dialog box and choose 0–9. A wild card metacharacter representing any digit from 0 318 through 9 () will appear in the Find box. Repeat this two more times, then type a hyphen (-) and then choose 0–9 four more times (or use copy and paste or drag and drop, if you wish). Your final expression (shown in Figure 11.8) can be stated, “Look for any sequence of three digits followed by a hyphen followed by four more digits.” If you click Find, Nisus Writer will locate and select the next phone number—no matter which digits it contains. While this was a very simple example (and in fact one that you could duplicate in other word processors), it does show you how easy it can be to look for patterns.

Figure 11.8. The PowerFind expression for “any phone number.”

Most metacharacters can only be included in Find expressions, and not in Replace expressions. The exceptions are the space, tab, return, and page break metacharacters; the Clipboard metacharacters; and the Found metacharacters. Why? When you replace something, you are essentially pasting over what used to be there. The thing you paste in has to be specific and unique (i.e., no variables), or it won’t make any sense. If you said, “Look for any word and replace it with any digit,” Nisus Writer would have no idea what you meant. On the other hand, you could logically say, “Look for any series of digits and replace it with a tab character,” since the tab character is not a variable. So don’t be surprised if some of the Find/Replace menu commands are dimmed in some contexts. As we discuss the metacharacters on each of the Find menus below, assume that they can only be used in the Find box unless otherwise specified.

319 The PowerFind Wild Cards

What is a wild card? Well, in most card games, a “wild” card is a special card like the Joker that you can use to represent any other card. If you have three aces and a (wild) Joker, you can treat the wild card as though it were another ace—or if a five would be more useful, it can represent a five. A wild card is a fantastically useful thing to have, because it can be used for just about any purpose. Wild cards in Nisus Writer are the same way. But unlike in card games where you have just one kind of wild card, in Nisus Writer you have many. The 0–9 wild card we just used is a special character that can stand for any digit at all (but only digits). The Wild Card menu (Figure 11.9) contains additional wild cards that can be inserted in your Find expression simply by choosing their names. They are all represented by the easy-to-understand metacharacters we’ve been talking about. Here’s what each wild card does:

Figure 11.9. The Wild Card menu in the Find/Replace dialog box.

Using Wild Cards

Great, you say. I know what they stand for, but how do I use them? The idea is to put wild cards together that form a generic pattern representing the specific thing you’re trying to find. There are several general principles that will help you to use wild cards effectively:

While wild cards by themselves (or in combination with typed-in characters) are very useful, you’ll often want to combine wild cards with metacharacters from the Special, Repeat #, and Position menus. We’ll look at those menus in a moment, but first, we must take a brief excursus.

What’s in a Word?

Although it may be fairly obvious to you and me what counts as a word, it can be tricky to explain this to a computer. And your software does need to know when something is a word. When you double-click, for example, Nisus Writer needs to know how much to select. When you use the Word Count command, it needs to know which things to count. And, of course, when you use the Any Word metacharacter, it needs to know which things to look for.

Obviously, a word can begin in a capital or lowercase letter, followed by any number of other letters. But how do 322 you know where the word stops? Well, there will generally be a space, tab, return, or punctuation character after a word. But there are still complications—what about “words” like AppleTalk, Joe’s, hoity-toity, 1st, $1,234.50, 25¢, or 50%? How do you deal with punctuation, unusual capitalization, and so on? Nisus Writer’s answer is that any of the above strings counts as a word. Words never include spaces or return characters, but they can include just about anything else, under the right circumstances. For example, strings of numbers are considered words, even if they include commas, decimal points, or %, $ or ¢ signs. But those signs must be in the proper place for numbers—%34, 18.roger, or Micro$oft would not be recognized as whole words by Nisus Writer.

The PowerFind Special Menu

Lots of word processors let you search for simple wild cards. But once we start looking at the choices on the Special menu (Figure 11.10), all new possibilities open up. For starters, Nisus Writer is the only word processor that will let you search for one thing or another thing at the same time, by choosing OR from the Special menu. OR allows you to match either of two (or more) items. When you insert an into your expression, Nisus Writer will treat everything on the left side of the as one possibility and everything on the other side as the other possibility. For example, if you search for thisthat, Nisus Writer will find any instance of the word “this” and also any instance of the word “that.” If you want to limit how much of the expression is seen by the , you need to use parentheses (see below under “The Match Menu” for details), in which case will recognize what’s on its left and right only up to the nearest parenthesis.

Figure 11.10. The Special menu in the Find/Replace dialog box.

Be sure not to put spaces on either side of the unless you specifically want to search for spaces. Every character typed into the Find box is significant.

323 You can use multiple ORs, as many as you like. It is perfectly acceptable to enter a string like thisthatthesethose, and it will do exactly what you’d expect—find any of those words. However, you must be careful when searching for things such that one of the options is the same as part of the other. Let’s say you enter the expression dentdentist, and that you have the Whole Word option unchecked. What do you think it will find (assuming both words occur in your document)? It will find every occurrence of “dent,” all right—including those that come at the beginning of the word “dentist” and inside words like “president” and “accidental.” But it will not actually find and select the entire word “dentist” anywhere in your document. Why? Because OR expressions are evaluated from left to right. If Nisus Writer finds what’s on the left of the OR, it is satisfied and stops there. If not, it goes on to see if it can find what’s on the right side (starting from the end of the current selection). So once it finds the “dent” in “dentist,” it has no reason to look further. If you want to find all instances of the word “dent” and all instances of “dentist,” then there are two ways to do it. First, you could turn on Whole Word, so that if it doesn’t find “dent” as a whole word it will still look for “dentist” as a whole word. The other strategy is to reverse the expression so it reads dentistdent. That way, if it finds “dentist,” it’s happy, but if it doesn’t, it will go on to see if it can find just “dent.” It will still find the “dent” in words like “president,” though—to narrow the search further, try something like dentistdent or dentistdent.

Below OR on the Special menu are other special characters you may want to include in a search. Choose to look for a return character, Space to look for a space character, or Tab to look for a tab character. While you can directly type a space character into the Find box, it is a better idea to use the metacharacter because this makes it much easier to read your expression. You cannot type a tab or return character directly, but if for some reason you really want to have an actual tab or return character in your Find box rather than their respective metacharacters, you can use Shift-Tab or Shift-Return, respectively, to enter them. The Space or Tab metacharacter finds, as you might have guessed, any space or tab character. It’s the same as entering . And 324 the Page Break metacharacter finds any forced page break (that is, one entered using the Page Break command on the Insert menu).

In case you’re curious, Shift-Tab and Shift-Return work even in Normal Find mode—which of course you’d never use, would you?

The Repeat # Menu

The Repeat # menu (Figure 11.11) has just three unassuming metacharacters on it, but it is incredibly powerful, particularly when used with wild cards. The metacharacters on the Repeat # menu specify how many times the preceding character, metacharacter, or parenthesized expression may appear. Let’s look at each one in turn and see how they’re actually used.

Figure 11.11. The Find/Replace dialog box’s Repeat # menu.

325 Some PowerFind Examples

Let’s look at a few simple examples of expressions that use metacharacters from the Wild Card, Special, and Repeat # menus to see how some of these things interact (Table 11.3).

Any Capitalized Word

Any Word or Phrase in Quotes

Two or More Returns in a Row

Any Digit or Tab Character

Any Two Digits, with an Optional Space Between Them.

Table 11.3. Sample PowerFind Expressions.

The Position Menu

Yet another unique feature of PowerFind is the ability to search for something based on where it is located in your document or with respect to other characters. Metacharacters representing position can be inserted using the Position menu (Figure 11.12). In addition to using these to narrow down the range of possible matches for a search, you can also use these metacharacters to move the insertion point to a different location in your document without selecting anything.

Figure 11.12. The Position menu in the Find/Replace dialog box.

326 Character on Left and Character on Right

The first two commands, Character on Left: and Character on Right:, cannot be used by themselves, but must be followed by a character or metacharacter. Let me explain how these commands work by way of a series of examples. If you wanted to move the insertion point to the right of the next letter j, you would enter the expression j. What this means is that the insertion point will be moved to the next point in your document such that the character on its left is j. Make sense? Similarly, an expression like would move the insertion point to the left of the next digit—i.e., to the next location such that the character on its right is a number from 0 through 9.

You are not limited to moving the insertion point; you can also use these to find and select strings. If this next part is a bit hard to get your brain around, bear with me—it’ll all become clear soon. The first thing to realize is that what can be said of an insertion point can also be said of a selection. That is, Character on Right refers to the character to the right of the insertion point; but if there is text selected, it refers to the character to the right of the selected region. So far so good? O.K., let’s suppose we want to find any word that is followed by another word beginning with s, but we don’t want to select any part of that next word. How would we do this? Simple: use an expression that says s. This reads, “Any word such that the immediately following character is an s.” And that’s just what it finds: any word such that the next word starts with an s. Easy.

But wait, you say. Isn’t the character immediately to the right of any word going to be a space, tab, return, or punctuation mark? Well…yes and no. The Any Word metacharacter is designed to select a word plus any spaces or tabs that immediately follow it. The program is trying to be helpful: if you do a Find/Replace that removes a series of words, you don’t want all the spaces that formerly separated them to be left behind. And if you change the format of a series of words, presumably you want the format of the spaces to change too. But the bottom line is that the Any Word metacharacter will always select a following space or tab (if there is one), but not any preceding blank characters. Feel better now? Let’s try some other variations.

327 Suppose we reversed the expression to read s. What do you think this will find? Surprise: it finds any word that begins with the letter s. That’s right. First it looks for a point in your document such that the character on its right is an s. Then it looks to see if what comes next is a “word.” If so, it selects it. If not, it moves on to the next s and keeps going until it finds a match. Now let’s try the same experiment with Character on Left:. The expression s will find and select any word whose last character is an s. Why? First it looks for any word. Then, it looks to see if the point immediately following the word (remember, PowerFind expressions are evaluated in left-to-right order) is such that the character on its left is an s. If so, it has succeeded and selects the word; if not, it moves on.

All right, one last example. You enter s. What does it find? Probably nothing. Oh no! Just when you were sure it would find any word such that the previous character is “s.” What went wrong? Nothing. But remember what I said earlier about the Any Word metacharacter. It will find following spaces and tabs, but not preceding ones. Virtually any word in your document will be immediately preceded by a space, tab, or return (and not an s), so this expression won’t find it. What you might try instead is the expressions.

Other Position Metacharacters

The remaining position metacharacters, unlike Character on Left: and Character on Right:, are quite straightforward. Each one of them can be used all by itself as a Find expression to move the insertion point to the next location described (i.e., the next word start, paragraph start, word end, etc.). Or they can be combined with other characters or metacharacters to build more complex strings. Here are some examples for each metacharacter:

The Clipboard Menu

Unlike the other metacharacter menus we’ve looked at so far, the Clipboard menu items (see Figure 11.13) can only be used in Replace expressions, not in Find expressions. With these metacharacters, you can replace some string that you find with the contents of one or more of your clipboards (possibly in combination with other text). The choices on the Clipboard menu are Current (which inserts the metacharacter) and #0 through #9. To replace something with the contents of the current clipboard (whichever one that may be), use Current; to use a particular clipboard by number, choose the number from the menu.

329

Figure 11.13. The Clipboard menu in the Find/Replace dialog box.

The Match Menu

And now we come to the final PowerFind menu: the Match menu (Figure 11.14). This is really cool and powerful, but difficult to describe. So let me give you two examples.

  1. You want to find any capitalized word, and replace it with the same word followed by a bullet (•). You don’t want to simply type a bullet into the Replace box, because that will erase your original word.
  2. You want to find any phone number, and make just the last four digits bold.

In both cases, we crucially need to refer to some part(s) of the expression we found. The Match menu gives us the capability to do that and more.

Figure 11.14. The Match menu in the Find/Replace dialog box.

330 Found Items

The first choice on the Match menu is Found, and this simply refers to whatever has been located by the expression in your Find box. For example, if your Find expression is , and when you click Find the word “meatball” is selected, then “meatball” is the “found” expression. If you enter all by itself in the Replace box, then clicking Replace will simply replace whatever was found with itself. However, you can also add things before or after to replace what you’ve found with additional text; apply fonts, sizes, and/or styles to to make those changes to your text, or even enter, say, to replace whatever you found with two copies of itself. The metacharacter always refers to the entire string that was found, regardless of any parentheses that were used.

Parentheses

The other important feature of the Match menu is that it contains special parentheses that let you group parts of your Find expression together. As you may have guessed, it’s no good just typing parentheses into the Find box, because Nisus Writer will assume that you’re looking for actual parentheses in your document. But the special large parentheses on the Match menu were made to group Find expressions. To insert an opening or closing parenthesis, choose it from this menu. There are two main reasons you’d want to group items with parentheses: to narrow your search, and to refer to parts of a found expression. We’ll look at each technique here.

Narrowing Searches

One reason to parenthesize parts of your expression is to give metacharacters like and a more specific domain of reference. For instance, if your Find expression read , Nisus Writer would find any string beginning with three or more digits in a row, for example, 186, 2121, and 4811477. But suppose you wanted to find any instance of one or more separate three-digit numbers in a row. You need to 331 put the number metacharacters in parentheses: and also be sure to check Whole Word (so that it doesn’t find 123456789, which is three 3-digit numbers in a row!). PowerFind treats anything in parentheses as a single character for the purpose of Repeat # expressions, so it will find any instance of a three-digit number one or more times. Parentheses are also useful in conjunction with . The expression California and AlaskaTexas will find “California and Alaska” or “Texas” but not “California and Texas.” However, if you add parentheses, you can turn it into California and AlaskaTexas, which will find “California and Alaska” or “California and Texas” but not “Texas” by itself. In short, parentheses make whatever’s inside them act as a single character, and also limit the range of material that can look at.

Referring to Parts of a Found Expression

The other main reason to use parentheses is so that you can refer to part of what you found in the Replace box. To take a fairly simple example, suppose you want to find any sequence of three italicized words in a row, and make only the second one bold. It’s easy enough to find three italicized words, using the expression (with the style Italic applied to the entire expression). But how do you refer to just the second word? Simple: put your metacharacters in parentheses, like this: . Now you have three separate items that can be found, and these can be referred to by number in your Replace expression. To refer to just the first parenthesized item in your Replace expression, choose (…Found 1) from the Match menu, which will insert the metacharacter into the Replace box. Repeat with (…Found 2) and (…Found 3). So far, you’ve said, “Look for these three (parenthesized) items, and replace them with the same three items in the same order.” But now, if you apply the style Bold to just the metacharacter, it will replace the first and third words with exact copies of what was found, and make just the second word bold.

This basic technique of parenthesizing parts of the Find expression and referring to them in the Replace expression 332 has a lot of possible variations. For example, you can rearrange the order of items simply by rearranging the order of the “Found” metacharacters. Or leave some of them out to delete part of your text instead of replacing it. And, of course, you can add text before, after, or between the “Found” metacharacters to expand your options still further.

When using parentheses, there are a few things to keep in mind. First, not everything in your Find expression needs to be parenthesized. If you leave a portion of the Find expression out of parentheses, it simply won’t create a “Found” replacement. In other words, the only parts of your Find expression that are referred to with the “Found” metacharacters are those parts in parentheses. Second, you can freely nest parentheses to form a complex expression. If you have a series of nested parentheses and you want to figure out which “Found” number refers to which portion of your expression, just remember that “Found” sets are counted from left to right, based on the position of the opening parenthesis. So in an expression like stuffmore stuff, (…Found 1) will refer to the entire expression (that is, everything enclosed in the set beginning with the first open parenthesis), and (…Found 2) will refer to just what’s in the inner set. Likewise, if you have stuffmore stuff, (…Found 1) will still refer to the entire expression and (…Found 2) to the inner set. If you add more parentheses, either within the existing sets or before or after, you simply need to count opening parentheses from left to right to determine what your “Found” expression should be.

A novel use of the “Found #” metacharacters is to include them in the Find box (rather than the Replace box) to search for duplicated items. For instance, the Find expression will find any cases of the same word twice in a row.

PowerFind Pro: Find Everything Else

As I mentioned above, one of the marvelous improvements in Nisus Writer 5.1 is that PoweFind now has all the capabilities of PowerFind Pro. However, I still use PowerFind Pro because it’s so much faster to type in metacharacters by hand than to build them using the menus in the Find/Replace dialog box. Your mileage, of course, may vary.

You’re probably feeling pretty powerful now that you have PowerFind under your belt. But wait—there’s more! While PowerFind is both powerful and easy to use, it does have some limitations. For example, say you want to find any word that doesn’t contain the letters a or e. The only way to do this in PowerFind would be to say, “look for any series 333 of (b OR c OR d OR f…[all the way to the end of the alphabet]), one or more times.” Pretty awkward at best. Wouldn’t it be nice if you could just say, “look for any sequence of characters, none of which is a or e, one or more times”? With PowerFind Pro, you can! In fact, you can do much more than that. Let’s look at the way PowerFind Pro works in general, then turn to some specific examples.

PowerFind Pro Fundamentals

Contrary to appearances, PowerFind Pro is not a lot harder than regular PowerFind. It does take a bit of getting used to, but fortunately you can still use all the things you’ve learned about PowerFind. For starters, the Find/Replace dialog box in PowerFind Pro mode looks exactly the same as PowerFind mode. All the menu choices are exactly the same, too. This should provide you with a bit of comfort. But there are differences—very important ones. The first big difference is that instead of the friendly PowerFind metacharacters you’ve grown to know and love (like or ), you’ll be using more compact, yet harder-to-read, metacharacters like and \r. All of the metacharacters you learned in PowerFind are still available, of course—they just look different. The second difference is that you have many more options available. While the menu choices are the same, there are a lot of additional metacharacters that you can type in yourself that give PowerFind Pro far more power and flexibility than plain old PowerFind.

Let’s try two simple exercises. First, open your Find/Replace dialog box and make sure it’s in PowerFind Pro mode. Choose Any Character from the Wild Card menu. Instead of seeing , the only thing that will appear is a period (.). Not too intimidating, eh? In PowerFind Pro, a period is the metacharacter that means “any character.” It works just like the metacharacter in PowerFind. You may ask, “But what if I actually want to find a period?” Since a lot of characters (particularly punctuation) have a special meaning in PowerFind Pro, we need a method to tell it when we’re looking for the literal versions of these characters. To do this, all you do is put a backslash (\) in front of 334 the character. So to look for an actual period, you’d use the expression \. (a backslash followed by a period). And what if you want to look for a backslash? Simple: type in two backslashes (\\) and you’re in business.

You’d probably like to know exactly which characters have a special meaning in PowerFind Pro. Here’s the list: . : [ ] < > \ | + - $ ^ & * 
(Other characters have special significance too, but only when combined with one of these.)

Here’s our second exercise. In your Find/Replace dialog box, make sure you’re in PowerFind mode this time. Using the menus, enter (“any sequence of one or more capital letters followed by a space, at the beginning of a paragraph”). Now, change the Find method to PowerFind Pro. Poof! Your expression has automagically become ^:a+\s (but the meaning stays the same). All your PowerFind metacharacters have been converted to their PowerFind Pro equivalents. Specifically, ^ means “paragraph start”; :a means “any uppercase alphabetic”; + means “one or more times”; and \s means “space character.” While you will soon become proficient enough at PowerFind Pro to avoid this extra step, it’s nice to know you can do this if you need to. (Unfortunately, though, it doesn’t work in reverse!)

So that’s pretty much the idea of PowerFind Pro: funny-looking metacharacters, and more of them, but they work the same way. As before, you can apply fonts, sizes, and styles to PowerFind Pro metacharacters, and you can also keep oft-used expressions in your glossary. The choices you had before are still on the menus, though choosing them inserts a different kind of metacharacter than it did before. And of course, you don’t have to use the menus at all—you can type all your PowerFind Pro metacharacters in manually (which is generally a lot quicker).

PowerFind Pro Metacharacter Equivalents

The first thing you’ll want to know when experimenting with PowerFind Pro is what the equivalent metacharacters are for PowerFind expressions. A complete list, with explanatory details, is found in Appendix C. For now, Table 11.4 gives a basic list of the available menu choices, and what they produce in both PowerFind and PowerFind Pro modes. Remember, these metacharacters have exactly the same functions as the ones in PowerFind, but you can’t use PowerFind Pro metacharacters in PowerFind mode—they’ll be interpreted as literal text.

335 Menu Command

PowerFind metacharacter

PowerFind Pro metacharacter

Any Character .
Any Character or ¶ :.
Any Word

:(\<:w:+\>:b*:) or (option-x)

Any Text :.+
A-Z a-z :a
A-Z a-z 0-9 :n
0-9 :d
a-z :l
A-Z :u
European

: (option-d)

OR |
\r
Space \s
Tab \t
Space or Tab :b
Page Break \f
0+ *
1+ +
0 or 1 -
Character on Left: :<
Character on Right: :>
Word Start \<
Line Start :^
¶ Start ^
Document Start :s
Word End \>
¶ End $
Document End :e
Current \CC

#0 to #9

to

\C0 to \C9

Found &
( \(
) \)

(…Found 1) to (…Found 9)

to

\1 to \9

Table 11.4. Metacharacters for Find/Replace menu choices in PowerFind and PowerFind Pro.

336 Other PowerFind Pro Metacharacters

In addition to the menu choices we still have, there are all-new metacharacters available in PowerFind Pro that do not appear on any menu (and therefore must be typed in manually). Again, a complete list of these can be found in Appendix C, and I will not repeat the whole list here. I will, however, mention a few that may be of particular interest in Table 11.5.

Name

Metacharacter

What it matches

Any Gremlin

:!

All “control” and upper-ASCII characters

Any alphabetic or underscore

:A

Upper- and lowercase alphabetics, plus the underscore (_)

Any hex character

:h (or :x)

Any number from 0–9 and any letter A–F or a–f

Any non-diacritical

(Option-Shift-D)

Opposite of :; any character unmodified by diacriticals

Backspace

\b

Backspace character (ASCII 8)

Linefeed

\v

Linefeed character (ASCII 11)

Table 11.5. Some of the metacharacters that are only available in PowerFind Pro.

Looking for Sets

One of the neatest things you can do in PowerFind Pro is “design your own wild cards” using sets. A set is simply a list of characters that will (or will not) be searched for at a particular point in your Find expression. For example, let’s say you wanted to look for any of the following characters: A, n, r, 2, 9. You could use the “brute force” method of using a bunch of OR’s: \(A|n|r|2|9\). But there is an easier way, and that is to enclose the characters you want to look 337 for in square brackets: [Anr29]. That’s all there is to it: you’ve just created a new metacharacter that matches all and only those characters you listed. This set can be used in your Find expression just like any other metacharacter. For instance, to find any word beginning with one or more of those characters, you’d use the expression \<[Anr29]+ in your Find box.

Sets can also include ranges of characters. For instance, if you wanted a metacharacter that would match all the digits from 3 to 9 inclusive and all the lowercase letters from a to w inclusive, you’d simply include those ranges, separated by hyphens, in your set: [3-9a-w]. But perhaps the most useful thing you can do with sets is specify anything not in a particular set. For example, let’s say you want to look for any character that is not A, X, or Z. All you need to do is put those characters between square brackets as usual, but with a caret (^) as the first character: [^AXZ]. This expression will match anything not in the set [AXZ].

By default, sets do not match the return character. So the set [^abc] will not match the return character, even though it is clearly “not in the set [abc].” To include the return character, simply put a colon before the set. So the set :[abc] will find any of the characters a, b, c, or a return; the set :[^abc] will find the return character and anything else that is not an a, b, or c.

There are a couple of other things you should know about sets. Most importantly, sets generally cannot contain metacharacters. It is tempting sometimes to try to make a set like [^:u] (to mean “anything that’s not an uppercase character”), but unfortunately you can’t; the colon and u are taken literally. You would have to express that set as [^A-Z]. The other important thing to remember about sets is that a few characters (^, [, ], :, - and \) have a special meaning in sets, and so can’t be typed in as set members directly. To include one of these characters in a set, precede it with a backslash (\). So a set that finds all and only the “special” set characters would look like this: [\^\[\]\:\-\\]. On the other hand, the metacharacters \s for space and \t for tab are acceptable within sets and retain their usual meanings.

There is actually one case in which you can put a return (\r) inside a set and it will be recognized, even if there is no colon in front of the set. This case is when the set is preceded by either “Character on right:” (:>) or “Character on left:” (:<). For some reason, if you have an expression in which either of these two metacharacters is followed by a set beginning with a colon, no match will occur. So, for example, to move the insertion point to the left of the next character that is a return, an “A,” or a “7,” use this expression: :>[\rA7].

338 Looking for the Shortest Match

Another PowerFind Pro distinctive is the ability to find the shortest match for some expression. For example, let’s say you want to find any sequence of one or more characters up to and including the first tab. You know that there might be several tabs in a row, and you only want to find the first one. The first thing you might try is an expression like .+\t (“any character, one or more times, followed by a tab”). But there’s a problem: the tab is part of “any character!” So this expression will find everything from your current insertion point to the last tab in the string. Yuck! What we need is a way to say, “Find the shortest sequence of any character, one or more times, followed by a tab.” This is done by putting a colon (:) immediately before the Repeat # metacharacter (in this case, the + sign). So the new expression looks like this: .:+\t (“any alphanumeric character, one or more times, up to the first instance of a tab”). The colon can also be used before “zero or more times” (:*) or “zero or one times” (:-) to indicate the shortest match in those environments.

If your goal is to find everything up to and including the first tab, you can use the expression [^\t]*\t as an alternate strategy.

Parentheses Galore

As you know from working with PowerFind, you can parenthesize up to nine different parts of your expression and refer to them individually. To enter parentheses in a PowerFind Pro expression, you must precede them with a backslash. So opening and closing parentheses become \( and \), respectively. You can also refer to “Found” items—the metacharacter for “Found” is & and “Found 1” through “Found 9” are \1 through \9. But in PowerFind Pro, you are not limited to just nine parenthesized items. You can have up to 63! To refer to “Found 10” through “Found 63,” use the metacharacters \E10 through \E63. In addition, PowerFind Pro offers a way to parenthesize part of your expression without creating a Replace expression (that is, without making it a “Found” item). To do this, precede your opening and closing parentheses with a colon instead of a backslash: :( and :).

339 PowerFind Pro Examples

Now that we’ve seen all the pieces, let’s look at some ways to put them together. First, let’s repeat the simple PowerFind examples we saw earlier, this time in PowerFind Pro format:

:u:l+

Any Capitalized Word

+”

Any Word Or Phrase In Quotes

\r\r+

Two or More Returns in a Row

:d|\t

Any Digit or Tab Character

:d\s-:d

Any Two Digits, with an Optional Space Between Them

Table 11.6. Sample PowerFind Pro Expressions.

Now let’s add some of the unique PowerFind Pro features. Here, for your finding pleasure, are some very useful PowerFind Pro expressions I’ve discovered. These “giant wild cards” can, in turn, be used in larger Find expressions if you like.

All of these examples are included in a glossary file on the CD-ROM so you don’t need to type them in by hand!

Summary

As you can see, the possibilities for what you can find with PowerFind and PowerFind Pro are nearly endless, and we’ve only just scratched the surface here. But if you try out the examples in this chapter and experiment a bit, you’ll soon find that you can search for just about anything you can describe in words. You’ll also find a lot of examples of Find/Replace in Chapter 12, which covers macros and glossaries. Speaking of which…if you think PowerFind Pro can make your life a lot simpler, just wait ’till you start experimenting with macros. In Chapter 12, we’ll explore the many ways macros enable you to get more done with less effort.

Copyright © 1995, 1996, 1999 by Joe Kissell

< Previous Chapter | Next Chapter >