Finding and Replacing Text
You can search for a term in the entire document or within a text selection. To start a search in SQL Editor, press Ctrl+F or select the menu command Edit | Find. You can enter a string or use the combo box to select a string from one of the last 10 strings. When you enter or select a string, all matches are highlighted, and the positions of the matches are indicated by orange markers in the scroll bar (see screenshot below). The position of the currently selected match (highlighted in gray) depends on where the cursor was last located.
You can see the total number of matches and the index position of the currently selected match. Use the (Previous) and (Next) buttons to switch between the matches. To switch between the Find and Replace modes, click the button.
Find options
You can specify find criteria with the help of the buttons located under the search field. The list of the available options is given in the table below.
Option | Icon | Description |
---|---|---|
Match case | Does a case-sensitive search: e.g., Address is not the same as address. | |
Match whole word | Only identical words will match. | |
Use regular expression | If this option is toggled on, the search term will be read as a regular expression. See Regular expressions below. | |
Find anchor | The position of an anchor depends on the place where the cursor was last located. Clicking the Previous and Next buttons does not change the position of the anchor. | |
Find in selection | A selection is a marked piece of text. To find a term within a selection, mark a piece of text, press Ctrl+F, make sure the Find in selection button is pressed, and type the term in the search field. |
Regular expressions
You can use regular expressions to find a text string. To do this, switch on the Use regular expressions option (see table above). Then enter a regular expression in the search field. Clicking (Regular Expression Builder) gives you a list of sample regular expressions (see below). The screenshot below shows a regular expression that helps find email addresses.
Regular expression metacharacters
The table below shows metacharacters that you can use to find and replace text. All the metacharacters except for the last two correspond to the menu items in Regular Expression Builder (see above).
Menu item | Metacharacters | Description |
---|---|---|
Any Character | . | Matches any character. This is a placeholder for a single character. |
Character in Range | [...] | Matches any characters in this set. For example, [abc] matches any of the characters a, b or c. You can also use ranges: e.g., [a-z] for any lower case character. |
Character Not in Range | [^...] | Matches any characters not in this set. For example, [^A-Za-z] matches any character except an alphabetic character. |
Beginning of Word | \< | Matches the beginning of a word. |
End of Word | \> | Matches the end of a word. |
Beginning of Line | ^ | Matches the beginning of a line unless it is used inside a set (see above). |
End of Line | \$ | Matches the end of a line. For example, A+\$ matches one or more A's at the end of a line. |
Tagged Expression | (abc) | The parentheses mark the start and end of a tagged expression. Tagged expressions may be useful when you need to tag ("remember") a matched region to refer to it later. Up to nine sub-expressions can be tagged and then back-referenced later.
For example, (the) \1 matches the string the the. This expression can be explained as follows: Match the string the and remember it as a tagged region; the expression must be followed by a space character and a back-reference to the tagged region matched previously. |
0 or More Matches | * | Matches zero or more matches of the preceding expression. For example, Sa*m matches Sm, Sam, Saam, Saaam and so on. |
1 or More Matches | + | Matches one or more occurrences of the preceding expression. For example, Sa+m matches Sam, Saam, Saaam and so on. |
\ | Where n is 1 through 9, n refers to the first through ninth tagged region (see above). For example, if the search string is Fred\([1-9]\)XXX and the replace string is Sam\1YYY, when applied to Fred2XXX, this will generate Sam2YYY. | |
\x | Allows using a character x, which would otherwise have a special meaning. For example, \[ would be interpreted as [ and not as the start of a character set. |
Replace text
To replace text, follow the instructions below:
1.Open the Replace dialog: Press Ctrl+H or select the menu command Edit | Replace. Alternatively, you can switch to Replace mode of the Find/Replace dialog by clicking the button in the top left corner of the dialog.
2.Enter the string you would like to replace in the Find field and enter the new string in the Replace field.
3.The Replace Next and Replace All buttons are located to the right of the Replace field. If you click Replace Next, one of the following happens: (i) If the cursor is located near a match or inside a match, the match is replaced; (ii) if the cursor is located outside a match, the cursor jumps to the next match. Click Replace All to replace all matches.
Replace text within a selection
To replace text within a selection, take the steps below:
1.Mark a piece of text.
2.Toggle on the Find in selection option.
3.Enter the Find and Replace text strings.
4.Click Replace Next or Replace All as required.
To undo the replace action, press Ctrl+Z or select Edit | Undo.
Find and replace special characters
If the Use regular expressions option is enabled, you can search for any of the following special characters within the text:
•\t (Tab)
•\ (Carriage Return)
•\ (New line)
•\\ (Backslash)
For example, to find a tab character, press Ctrl + F, select the Use regular expressions option, and enter \t in the Find dialog box.
The special characters above can also be used as replacement text. For example, to replace all occurrences of semi-colons by carriage returns within the text A;B;C;D, use the following find and replace options:
The outcome is shown below:
A
B
C
D