Red Hat Docs > Manuals > EDK Manuals > |
The Source-Navigator Grep tool allows you to search for text patterns in source files throughout the project. It is more powerful than using grep at the command line because it:
saves results of multiple searches, so you can review them later.
provides "one-click" Editor access to the lines of code matching your search.
To search for text patterns in the name of the symbols in the database, use the Retriever tool. For more information, see Retriever.
Start the Grep tool from the Windows menu by selecting New View -> Grep-Editor. This opens a Grep/Editor split window (for more information on split windows, see Adding a Browser to an Existing Window).
In the Pattern text box, enter a regular expression then click the Search icon. For more information on regular expressions, see GNU Regular Expressions.
You can use the Files filter to limit your search; for example, entering *.c restricts the search to only C files. For a list of file extensions and their associated languages see Pattern Interpretation of Special Characters. Sample Grep Search Results shows the results of a sample Grep search.
Clicking on an item in the Grep window displays the appropriate file in the Editor, with the cursor positioned at the selected line.
To step through the Grep results, click the left or right black arrow keys in the toolbar. To filter your Grep results, use the Format combo-box to select an option.
A GNU regular expression1 is a pattern that describes a set of strings. Regular expressions are constructed like arithmetic expressions: various operators combine smaller expressions to form larger expressions.
An ordinary character is a simple regular expression that matches a single character and nothing else. For example, f matches f and no other string. You can concatenate regular expressions together. For example, foo matches foo and no other string.
You can combine regular expressions with regular expression operators, or metacharacters, to increase the versatility of regular expressions. Traditional expression characters are enclosed by brackets [ and ].
For example, [Aa]pple matches either Apple or apple. A range of characters is indicated by a dash -. [a-z] matches any lowercase letter and [0-9] matches any digit string between 0 and 9. You can string groups together, so that [a-zA-Z0-9] matches any single alphanumeric character.
To represent the - dash itself, it must be the last character, directly succeeded by the ]. To represent ] bracket, it must be the first character after the [ or the [^.
Special Characters lists special characters and examples of how to use them.
In the | (pipe) example above, notice that foo|bar is matching either foo or bar. It's not matching o or b, resulting with either fooar or fobar.
Certain named classes of characters are predefined, but can only be used within bracket expressions.
For example, [[:alnum:]] means [0-9A-Za-z] in the C-locale, except the latter form is dependent upon the ASCII character encoding, whereas the former is portable.
A regular expression matching a single character may be followed by one of several repetition operator:
Some characters cannot be included literally in regular expressions. You represent them instead with escape sequences, which are characters beginning with a backslash ( \). A backslash is also part of the representation of unprintable characters such as a tab or newline.
Two regular expressions may be concatenated; the resulting regular expression matches any string formed by concatenating two substrings that respectively match the concatenated subexpression. For example:
The backreference \n, where n is a single digit, matches the substring previously matched by the nth parenthesized subexpression of the regular expression. For example, \(ab)c\1 matches abbbcabbb, but not abbbcabb.
For additional information on regular expressions, please refer to a reference text such as Mastering Regular Expressions2.
1. Richard Stallman and Karl Berry wrote the GNU regex backtracking matcher. Copyright © 1989, 1991 Free Software Foundation, Inc., 675 Massachusetts Avenue, Cambridge, MA 02139, USA. Return to text.
2. Friedl, Jeffrey E. F. 1997. Mastering Regular Expressions. ISBN 1-56592-257-3.
| ||
---|---|---|