Find and Replace Strings in Code
To search for a string in code, place the cursor in the code editor, then press Ctrl+F to open the Quick
Search box in search mode, or Ctrl+H to open it in replace mode. Alternatively, use the appropriate command from the context menu. To toggle between the two modes, click the up or down icon, or press Ctrl+F or Ctrl+H.
The search is restricted to the code
of the current object.
- To find a string, type it in the search
field and click the Search button or press Enter.
The next occurrence of the string (if found)
is displayed and selected in the Code Editor. If the string is not found, this is reported
in the Messages tab.
- To find and replace a string, type the search string in the search field and the replace string in the replace field. Then click the Replace button.
The next occurrence of the search string (if found)
is displayed and selected in the Code Editor.
Click the Replace button again to replace the selected text with the replacement string, and then search for the next occurrence of the search string.
If the search string is not found, this is reported
in the Messages tab.
- To replace all occurrences of a search string, type the search string in the search field and the replace string in the replace field. Then click the All button.
All occurrences of the search string are replaced by the replace string.
The Messages tab shows the number of replacements made. If the search string is not found, this is reported
in the Messages tab.
- To set search options, click the option to
switch it on or off.
- To search using regular expressions, you can
use the following symbols:
Symbols for Regular Expressions. | Matches any character |
\( | Marks the start of a region for
tagging a match. |
\) | Marks the end of a tagged region. |
\< | Matches the start of a word. |
\> | Matches the end of a word. |
\X | Use a character X
that would otherwise have a special meaning. For example, \[ is interpreted as
[ and not as the start of a character set. |
[...] | Defines the set of allowed characters
to match. For example, [abc] means any of the characters a ,
b or c . You can also specify a range of
characters. For example, [a-z] matches any lower case character. |
[^...] | Defines the set of characters to be
excluded from the match. For example, [^A-Za-z] means any character except an
alphabetic character. |
^ | Matches the start of a line (unless
used inside a set (as defined by [] ) |
$ | Matches the end of a line. |
? | Matches zero or one times the
specified character. For example, Sa?m matches Sm or
Sam . |
+ | Matches 1 or more times the specified
character. For example, Sa+m matches Sam , Saam ,
Saaam and so on. |
* | Matches 0 or more times the specified
character. For example, Sa*m matches Sm , Sam ,
Saam , Saaam and so on. |
Examples of regular expressions in searches
- Find where a variable (
sum
) is assigned a value: ^\s*sum\s*=
- Find where a variable (
sum
) is used: \<sum\>
.
The use of \<
and \>
, which match the start and end of a word respectively, ensures that the expression won’t find strings like SUMMARY
, CHECKSUM
or CONSUMPTION
.
- Remove trailing blanks:
\s+$
then replace with nothing.
- Update string substitution syntax:
%%([^%]+)%%%
then replace with:
%%(\1)
For more information, see Substitution in String Values.