305 Chapter 11. Find & Replace
In this chapter, youll learn
Every time someone asks me whats 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 programseven the Finderallow 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 Ive a shred of sanity left after all. After all, were 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 isbut with more gadgets and horsepower than you ever thought 306 youd need! When you start to use Nisus Writers Find/Replace for the first time, youll 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 youll 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 Writers 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, theres one command for Find and another for Replace (which is actually Find and Replace, of course). This has always struck me as a bit oddif 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. Thats why I talk about Find/Replace as if its 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/ReplaceNormal Find, PowerFind, and PowerFind Pro. You might think of these as the Beginner, Advanced, and Way Advanced methodseach 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 dont think theres any particular reason to use Normal Find at all, so I wont say much about it. Well concentrate on PowerFind and PowerFind Pro in this chapterbut first, lets look at what these terms really mean.
Nisus Writers 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. Heres 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.
PowerFind, the Find/Replace dialog box expands to give you additional options (Figure 11.4). In addition to plain or styled text, you can search for wild cards (Any Uppercase Letter, Any Word, etc.) and special characters (space, tab, return, page break). You can specify position (beginning of word, end of paragraph, etc.) and number of repeats, use OR to look for different kinds of things at the same time, and parenthesize parts of your expression to treat each part differently when replacing. And you can use the contents of any of your clipboards in your Replace expression. PowerFind expressions are friendly 


)
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 onall 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. |
Which mode should you use? Well, it depends. Normal Find is used by default when Nisus Writer is installed. But as I said above, theres 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 (dont forget to set this as a preference as well). You wont give up any capabilities, but youll have a constant reminder that other options are available to you.
There will be times youll 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 thats not part of a certain set of characters (theres 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 dont 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 PowerFinds capabilities, youll probably switch to PowerFind Pro sooner or later.
Performing a Basic Find/Replace
Now that we know what were dealing with, lets 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 youre not already in PowerFind mode, choose PowerFind from the Find Method pop-up menu. To do a basic search, type whatever youd like to find (which well 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 whatevers 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 |
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 Writers Find/Replace dialog box, its 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 its 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 youve 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.
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.
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 youve 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 youre 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 youve typed in the Find boxhandy if you dont 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, youll match résumé in your document, and vice-versa.
|
|
The |
Amazing but true: you can actually search for character graphics (including tables, equations, and the like) using Nisus Writers Find/Replace. Theres 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 wont 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 youve pasted in and choose Any Size from the Size menu.
|
|
You can find character graphics even in Normal Find mode, but of course, if youve read the past few pages, youre 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 cant 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 |
|
|
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.
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 its found something but nothing appears to be highlighted, you might want to turn on Invisible Text to see if it found something you cant see.
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 didnt like.) Metacharacters allow you to match patterns of characters in your text, and theyre the building blocks of PowerFind and PowerFind Pro expressions. PowerFind metacharacters are easy to read
)
). When youre 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 ( |
PowerFind: Find Almost Anything
By way of introduction to PowerFind, lets say youve 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 dont 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.
Heres how we do it: First, with the Find/Replace dialog box open and in PowerFind mode, pull down the Wild Card menu thats inside the Find/Replace dialog box and choose 09. A wild card metacharacter representing any digit from 0 318 through 9
)09 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 numberno 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 wont 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 dont 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.
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 aceor 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 09 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 weve been talking about. Heres what each wild card does:

Figure 11.9. The Wild Card menu in the Find/Replace dialog box.
Any CharacterMatches any character except the return character.
Any Character or ¶Matches any character at all, including the return character.
Any WordMatches any string of characters that Nisus Writer identifies as a word. See below under Whats in a Word? for an exact description.
Any TextMatches any character, including the return character, any number of times. Equivalent to 320 Any Character or ¶ followed by 1+ from the Repeat # menu.
AZ azMatches any upper- or lowercase alphabetic character, including those that have been modified with diacriticals (e.g., é, ñ, Å, Î, etc.).
AZ az 09Matches any upper- or lowercase alphabetic character, with or without diacriticals, plus any digit from 0 through 9.
09Matches any digit from 0 through 9.
azMatches any lowercase alphabetic character, including lowercase characters that have been modified with diacriticals (e.g., é, ñ, å).
AZMatches any uppercase alphabetic character, including uppercase characters that have been modified with diacriticals (e.g., É, Ñ, Å).
EuropeanMatches any upper- or lowercase alphabetic character that has been modified with a diacritical (but not unmodified characters).
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 youre trying to find. There are several general principles that will help you to use wild cards effectively:
AZ az 09 wild card instead of 09 to locate a number. The problem is, since alphabetic characters are also included in this wild card, we might also find things like Joe-Dave or pre-1996. So be as specific as you can.
Any Word and Any Text, wild cards match exactly one character at a time. So if youre looking for a string that has a specific number of characters (like our telephone number example), be sure to repeat the wild card character the appropriate number of times.
09 twice.
Any Word wild card, select the metacharacter, and apply the style Bold to it.
Any Text with caution. By itself, it will find your entire document! This wild card is most useful when combined with Position metacharacters (see below), or when it has a font, size, and/or style applied to it.
While wild cards by themselves (or in combination with typed-in characters) are very useful, youll often want to combine wild cards with metacharacters from the Special, Repeat #, and Position menus. Well look at those menus in a moment, but first, we must take a brief excursus.
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 complicationswhat about words like AppleTalk, Joes, hoity-toity, 1st, $1,234.50, 25¢, or 50%? How do you deal with punctuation, unusual capitalization, and so on? Nisus Writers 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.
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 this
that, 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 whats 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 |
323 You can use multiple ORs, as many as you like. It is perfectly acceptable to enter a string like this
that
these
those, and it will do exactly what youd expectfind 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. Lets say you enter the expression dent
dentist, 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 rightincluding 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 whats on the left of the OR, it is satisfied and stops there. If not, it goes on to see if it can find whats 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 doesnt 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 dentist
dent. That way, if it finds dentist, its happy, but if it doesnt, it will go on to see if it can find just dent. It will still find the dent in words like president, thoughto narrow the search further, try something like dentist

dent or dentist

dent.
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. Its 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 youre curious, |
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. Lets look at each one in turn and see how theyre actually used.

Figure 11.11. The Find/Replace dialog boxs Repeat # menu.
0+ means zero or more timesin other words, the preceding item may not be there at all, or it may be there any number of times. Lets say you want to look for any number beginning with the digit 3. This number may be a 3 all by itself, or it may have additional digits after it. To do this, youd enter the PowerFind expression 3
, meaning 3 followed by zero or more digits.
1+ means that the preceding character must appear at least once, and in addition may repeat any number of times. This is the most commonly-used repeat metacharacter. For example, if you enter
, youll find any single uppercase character. But if you then add
, youll find any sequence of one or more capital letters, like AAA or HTML.
0 or 1 means the preceding character may be there once or not at all. You might use this to find a telephone number that may or may not have a space before or after the hyphen: 




-




Lets 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.
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 digiti.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 meitll 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., lets suppose we want to find any word that is followed by another word beginning with s, but we dont 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 thats just what it finds: any word such that the next word starts with an s. Easy.
But wait, you say. Isnt 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 dont 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? Lets 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. Thats 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 lets 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 wont find it. What you might try instead is the expression
s
.
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:
Word StartFinds the beginning of a word. You might use something like 
pre to find any word beginning with the letters pre-. Or use 

to find any two spaces in a row immediately preceding a word.
Line StartFinds the beginning of the next line (not necessarily the next paragraph). 
will find any line beginning with a digit; 

will find any line beginning with one or more tabs.
¶ StartFinds the beginning of the next paragraph (that is, the point immediately after a return character). 
finds any paragraph that starts with a lowercase letter. 

finds any paragraph starting with one or more blank characters.
Document StartFinds the very beginning of your document. 
will find a return character that comes at the beginning of your document.
Word EndFinds the end of a word. Note that this is the real end of the word, not the space or tab character that may come after the word. 
? will find any question mark that immediately follows a word; ing
will find the next instance of -ing that comes at the end of a word!
¶ EndFinds the end of a paragraph. Unlike
,
places the insertion point immediately to the left of the return character that ends a paragraph. Use 
to find any word at the end of a paragraph.
Document EndFinds the very end of the document. Exeunt
will find the word Exeunt, but only if it is the last word in your document.
Unlike the other metacharacter menus weve 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.
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.
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.
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 youve 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.
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, its no good just typing parentheses into the Find box, because Nisus Writer will assume that youre 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 youd want to group items with parentheses: to narrow your search, and to refer to parts of a found expression. Well look at each technique here.
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: 





Whole Word (so that it doesnt 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 Alaska
Texas will find California and Alaska or Texas but not California and Texas. However, if you add parentheses, you can turn it into California and 
Alaska
Texas
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. Its 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, youve 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 wont 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 
stuff
more 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 whats in the inner set. Likewise, if you have 

stuff
more 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.
|
|
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 its 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. |
Youre probably feeling pretty powerful now that you have PowerFind under your belt. But waittheres 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 doesnt 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. Wouldnt 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. Lets look at the way PowerFind Pro works in general, then turn to some specific examples.
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 youve 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 differencesvery important ones. The first big difference is that instead of the friendly PowerFind metacharacters youve grown to know and love (like
or
), youll be using more compact, yet harder-to-read, metacharacters like and ![]()
\r. All of the metacharacters you learned in PowerFind are still available, of coursethey 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.
Lets try two simple exercises. First, open your Find/Replace dialog box and make sure its 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 were 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, youd 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 youre in business.
|
|
Youd probably like to know exactly which characters have a special meaning in PowerFind Pro. Heres the list: |
Heres our second exercise. In your Find/Replace dialog box, make sure youre 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, its nice to know you can do this if you need to. (Unfortunately, though, it doesnt work in reverse!)
So thats 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 dont have to use the menus at allyou can type all your PowerFind Pro metacharacters in manually (which is generally a lot quicker).
PowerFind Pro Metacharacter Equivalents
The first thing youll 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 cant use PowerFind Pro metacharacters in PowerFind modetheyll be interpreted as literal text.
|
335 Menu Command |
PowerFind metacharacter |
PowerFind Pro metacharacter |
Any Character |
![]() |
. |
Any Character or ¶ |
![]() |
:. |
Any Word |
![]() |
|
Any Text |
![]() |
:.+ |
A-Z a-z |
![]() |
:a |
A-Z a-z 0-9 |
![]() |
:n |
0-9 |
![]() |
:d |
a-z |
![]() |
:l |
A-Z |
![]() |
:u |
European |
![]() |
|
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 |
|
|
|
|
Found |
![]() |
& |
( |
![]() |
\( |
) |
![]() |
\) |
|
|
|
|
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 |
|
Any number from 09 and any letter AF or af |
|
Any non-diacritical |
:Î (Option-Shift-D) |
Opposite of : |
|
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.
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, lets 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 ORs: \(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]. Thats all there is to it: youve 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, youd 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, youd 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, lets 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 thats not an uppercase character), but unfortunately you cant; 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 cant 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 ( |
338 Looking for the Shortest Match
Another PowerFind Pro distinctive is the ability to find the shortest match for some expression. For example, lets 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 theres 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 |
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 itemsthe 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 :).
Now that weve seen all the pieces, lets look at some ways to put them together. First, lets 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 lets add some of the unique PowerFind Pro features. Here, for your finding pleasure, are some very useful PowerFind Pro expressions Ive 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 dont need to type them in by hand! |
\<\(1\s-\--\s-\)-\((-:d:d:d)-\)-\s-\--\s-:d:d:d\s-\--\s-:d:d:d:d\>- after each \s to a *.
[^\s\t][^!?\t\r]:+[.!?]:(:e|:>[\s\t\r]:)
Sentences are notoriously difficult to find, because they can contain quoted phrases and abbreviations like Mr. so that its hard to tell where they end. This expression, while not quite perfect, comes very close to finding any sentence.
:(:(:a+\://:)|:(mailto\::):)[^\s\t\r>]+:<[^\.,;?!"')]\(:N|[\.~!#$%\&\*\-\+]\)+@[^\s\t\r>]+:<[^\.,;?!]As you can see, the possibilities for what you can find with PowerFind and PowerFind Pro are nearly endless, and weve only just scratched the surface here. But if you try out the examples in this chapter and experiment a bit, youll soon find that you can search for just about anything you can describe in words. Youll 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, well 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 >