Shortcut key: SHIFT+F3
The Find command searches the active window for a text string. You can specify a whole-word match, an exact (case-sensitive) match, a general pattern search using regular expressions, and the direction in the file (up or down) to search.
·To find a text string:
1.From the Edit menu, choose Find. The Find dialog box appears.
2.Type the text string or regular expression in the Find What text box.
3.Set any search options you need.
4.Choose Find Next.
When you choose the Find command, the editor uses the location of the insertion point to select a default search string. If the insertion point is inside a word, that word is displayed as the search text in the Find What box.
If the insertion point is between words, the word to the right is displayed. If there is no word to the right, the word to the left is displayed. If that is not possible, nothing is displayed.
The drop-down list box to the right of the Find What text box records the last 16 text items you searched for. Select an item from the list to search for it again.
You can set any of the following search options in the Find dialog box:
Match Whole Word Only
Searches for complete occurrences of the text. A word contains only the char-acters a-z and A-Z, the numbers 0-9, and the # or _ (underscore) characters.
Match Case
Searches for text that matches the capitalization of the search text.
Regular Expression
Uses special characters to search for text. See the following section for more information.
Tag All
Searches for text and marks each line that contains the text. Use the Tag commands from the View menu to move to each marked line.
Direction
Up
Searches from the insertion point to the beginning of the file. When the beginning of the file is reached, the search restarts at the end of the file.
Down
Searches from the insertion point to the end of the file. When the end of the file is reached, the search restarts at the beginning of the file.
When text is found, the editor scrolls to the text and highlights it. The dialog box is replaced with a smaller version which displays just the dialog buttons. Select Find Next to continue the search. Choose Cancel to end the search and close the dialog box. When the entire file has been searched, a dialog box informs you the search has been completed.
A regular expression is a search string that uses special characters to match a text pattern in a file. In contrast, a literal search string finds a “literal” match with itself. Regular expression searches go beyond literal searches. For instance, you can use regular expressions to search for all the five-digit numbers in your source file or for all strings enclosed in quotation marks.
You can use eight special characters as regular expressions. They can be used separately or combined for more complex or precise matches.
The following list shows the characters that can be used as regular expressions.
Period ( . )
Matches: Any single character Example: log..
This example finds any occurrence of the string “log” plus two additional literal characters, such as “logic” or “log10.” The text pattern can occur in the middle of a word. For example “log..” will find “logar” in “logarithm” and “logic” in “biological.”
Caret (^)
Matches: Search text at the beginning of a line Example: ^int
The example finds “int” at the beginning of any line, such as this one: int matherr( struct exception *except )
However, because spaces are considered characters, int will not be found if it is indented by spaces or a tab.
Dollar Sign ($)
Matches: Search text at the end of a line Example: program$
The example finds the string “program” at the end of any line. This is a case where you may want to combine regular expression characters to increase the scope of your search. For example, the search string: program...$ finds “program. }.” A search with the regular expression “program$” would pass over this construction.
Asterisk (*)
Matches: Zero or more occurrences of the text preceding the asterisk Example: to*t
This example matches “tt,” “tot,” and “toot.”
Plus Sign (+)
Matches: One or more occurrences of the text preceding the plus sign Example: to+t
This example matches “tot” and “toot,” but not “tt.”
Brackets ([ ])
Matches: Sets of characters specified within the brackets Example: x[–+/*]y
In the example above, the regular expression matches “x+y,” “x–y,” “x/y,” or “x*y,” but not “x=y” or “xzy.” The special characters plus and asterisk do not function as regular expression characters within the brackets. The following two special characters can be used inside brackets:
Character | Use |
Caret (^) | Matches any character except those specified within the brackets. The caret must be the first character following the left bracket to be treated as a special character. |
Hyphen (-) | Matches characters in ASCII order between the characters on either side of the hyphen, including the delimiting characters. |
Backslash (\)
Interprets the next character literally Example: x\*y
This example finds “x*y.” Characters preceded by a backslash lose their special meanings and are treated literally.
NOTE:
To match a right-bracketed character, type a ] immediately after the right bracket that delimits the set of characters. For example, [c]].
Related Commands
Edit menu: Replace View menu: Next Tag, Previous Tag
See Also
Finding Text, page 18