Home » Support » Tutorials/Power Tips » UltraEdit » Using find/replace
IDM Power Tips

Find and replace, find in files, and replace in files

UltraEdit and UEStudio give you the ability to perform a find or replace through one or more files. There are multiple configuration options which allow you to target specific file types, project files, directories of files, and more. Using the available tools, you can customize your find or find/replace to quickly make changes to text or code in a directory of files, or to locate a unique string within a single file buried in hundreds of other files, and even find files that do not contain a specific string.

Find and replace, find in files, and replace in files

All of the search features covered here may be accessed under the "Search" menu.

Find and replace, find in files, and replace in files


Find

You can search your open file by selecting the "Find" option from the "Search" menu. Once you select this option, a dialog box will prompt you for your search terms. Here you can also specify other "find" options. To quickly search, type in what you are looking for and press "Find Next."

Find and replace, find in files, and replace in files

The first found string will be highlighted in the file while the Find dialog stays open. You can then step through all occurrences of the string in the file by pressing F3, which will take you to the next instance found. Press CTRL+F3 to return to the previous instance.

You are given several options in the find dialog that you can use to customize your search.

Match Whole Word Only

UltraEdit will not restrict a search to matching whole words only. This option restricts the search to whole words only. Whole words are words separated, on both sides, by a space.

For example, select this option if you want to search for 'a', or 'A' without finding all words that include 'a'.

Match Case

By default your search will not be case sensitive. Selecting "Match Case" will result in UltraEdit searching for only case-sensitive matches.

Regular Expressions

A regular expression search allows you to search for strings that are different but are composed of a similar pattern. For instance, in the below example, our search string of "<.*>" is a special syntax that will match ANY string composed that begins with "<" and ends with ">".

Find and replace, find in files, and replace in files

This search is done using Perl-style regular expressions, which may be configured in Advanced : Configuration : Search : Regular Expression Engine, or by clicking on the Advanced button (on the find dialog) and selecting the particular engine.

The "." in our search string tells UltraEdit to find any character that is not a new line, and the "*" character qualifies that by telling UltraEdit to search for this and match it 0 or more times. Therefore, all of the following strings would be matched:

  • <>
  • <a href="#top>
  • <img src="images/powertips/ue/search4.png" alt="UltraEdit Searches" border="0">

However, the following string would not be matched since it contains a line break (new line). While the "." character will match any character, it will not match a line break.

  • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">

Click here to find more information on Perl-style regular expressions. Additional information about regular expression syntax is available in the Help file under the "Regular Expression Engine" section.

Find Where

Current File

If you select this option, UltraEdit/UEStudio will perform the search in the current file.

Selected Text

If you select this option, UltraEdit/UEStudio will ONLY search in the currently selected text.

Find Next through all opened files

If you select this option, repeating the Find Next command (F3) will continue to cycle through all open files after finishing the search through the active file.

Beyond the optional items available in the top-level of the Find dialog, there are also Advanced configuration items available. To view the Advanced options, click on the Advanced button.

Using Find, Replace, Find In Files, and Replace in Files

Regular Expression Engine

UltraEdit/UEStudio supports 3 styles of regular expressions syntax - UltraEdit style, Unix Style, and Perl Compatible Expressions. Additional information about the specific syntax is available in the Help under the "Regular Expression Engine" section.

Highlight All Items Found

This option will result in all items matching the search string to be highlighted, or shown as selected text, when the Find Next button is pressed.

List Lines Containing String

Selecting this option will cause UltraEdit to search for all occurrences of the string in the active document and list them in a dialog box. When the list lines containing string dialog opens, you can double-click on a result line and UltraEdit will position to that line in the file. You may also select the result line and click on Goto.


Count All (Count Occurrences)

This button will count the number of occurrences of your search string in the active file.

Find and replace, find in files, and replace in files


Recent Search History

If you would like to view the recent search history, you can select the entire text (Select All - CTRL + A) of the Find dialog and press the up/down arrow to cycle through the history. Additionally, you can click the clock icon to select an item from your search history.

Using Find, Replace, Find In Files, and Replace in Files

UltraEdit/UEStudio also offers a convenient toolbar item that allows you to scroll through a drop-down box of your recent searches. This is especially useful if you need to access a recent search quickly. You can select the search item you need, then press F3 to find the next instance of this search, all without invoking the Find dialog.

Using Find, Replace, Find In Files, and Replace in Files


Search Favorites

The star icon on the Find/Replace dialog allows you to save a list of your favorite searches. This can be especially useful for complex regular expression patterns.

To use an item stored in the favorites list, simply click the Star icon and navigate to Favorites, and select the item.

Using Find, Replace, Find In Files, and Replace in Files


Replace

The "Replace" option under the "Search" menu will invoke the Replace dialog. This allows you to search for a phrase or string and then replace it with a different phrase or string.

Using Find, Replace, Find In Files, and Replace in Files

There are several options for configuring your search in the Replace dialog. For our purposes, we will do a simple search and replace, replacing all occurrences of "1,000,000" with "2,000,000" as shown below.

Using Find, Replace, Find In Files, and Replace in Files

You can select "Replace All," and all instances of your string will be replaced immediately. However, we would like to see our matches before we replace them. To do this, we will press the "Start" button instead. This will find the first occurrence of our find string and highlight it, then bring up a smaller dialog with some replace options.

Using Find, Replace, Find In Files, and Replace in Files

After pressing the "Replace" button, our matched string is replaced. You can press "Replace All" to go ahead with the replace on all occurrences in the file immediately. Pressing the "Find Next" button will take you to the next occurrence of the string without replacing the current one. Pressing "Last" will take you to the last found string, and pressing "Close" will close the Replace dialog altogether; essentially canceling the replace.

As you can see below, our text in the document has been replaced with our replace string.

Using Find, Replace, Find In Files, and Replace in Files


Further Replace Options

There are some additional options and configurations unique to the Replace dialog when you first invoke a replace. The options for "Match Whole Word Only", "Match Case", "Regular Expressions", and "Replace Where" work the same as in the Find dialog (see above).

To see the additional (Advanced) options, click on the Advanced button.

Using Find, Replace, Find In Files, and Replace in Files

Preserve Case

The option to preserve cases causes will match the case of the replace string with the case of the found string. The rules for this are as follows:

  1. If the word found is all lowercase the replacement word will be all lower case
  2. If the word found is all UPPERCASE the replacement word will be all UPPERCASE
  3. If the word found is MixedCase the replacement word will MATCH the casing of the replacement word.

For example, if this option is selected and you search for "The" and replace it with "Then," the following replaces would occur:

  • "the" will be replaced with "then"
  • "THE" will be replaced with "THEN"
  • "The" will be replaced with "Then"

Replace All is from Top of File

If this option is selected the specified search will be executed from the top of the active file rather than the current cursor position. This setting is important because a "Replace All" could (potentially) skip a find/replace that is above the cursor position.

Close this dialog after replace

If this option is selected the dialog will close after the command has been executed.


Find in Files

The "Find in Files/Replace in Files" options are accessible under the "Search" menu. These powerful search options allow you to search for strings or text within multiple files contained in a directory.

Using Find, Replace, Find In Files, and Replace in Files

Selecting the Find in Files option will bring up a Find in Files dialog box. This box allows you to configure the parameters of the search.

Using Find, Replace, Find In Files, and Replace in Files

For our example, we would like to find the string "1,000,000" in all of our HTML files in our "htmlBackup" directory.

In Files/Types
Setting the "In Files/Types" to *.html tells UltraEdit to search ONLY HTML files. If you would like to search in multiple file types, you may list additional file types separated by semicolons (ie. *.html; *.txt; *.php).

Directory
You can click the "Browse" button to browse through your computer for the directory you'd like to search. If you wish to search sub directories, below the primary directory, make sure to select the "Search Sub Directories" option.

Once we press the find button, our search begins. On larger directories with many files, the search may take several minutes. By default, the results of our search will be written to an output window, as shown below.

As you can see from the below screenshot, every occurrence found is listed in the output window. Scroll down to see more occurrences. You may double-click the file path to be taken to the line in the file where the search string was found.

Using Find, Replace, Find In Files, and Replace in Files


Further Find in Files Options

The following options are unique to the "Find/Replace in Files" dialogs.

Unicode Search

Selecting this instructs UltraEdit to perform a Unicode search. The string you enter will be entered as multi-byte and converted to Unicode. All files searched will be searched for using the Unicode string.

Search In (Files Listed/Open Files)

Allows you to specify whether the search is conducted in the directory you've specified (Files Listed) or the files that are currently open in the editor.

You will need to click the Advanced button to use some of the options below.

Search Subdirectories

This instructs UltraEdit to search all subdirectories of the specified directory. By default UltraEdit will only search files within the top-level directory you specify.

Results to Edit Window

This option instructs UltraEdit to create an edit window (new file) for the results of the find. This allows you to edit, save, and print the results. As noted above, UltraEdit by default will capture the output in a list box window (Output Window) that allows you to double click on the result and have the file opened automatically.

Ignore Hidden Sub Directories

If this option is selected, the operation will ignore sub directories that are hidden.


Replace In Files

The "Replace in Files" option, located under "Find in Files" in the "Search" menu, is probably one of the most powerful Find/Replace functions in UltraEdit. This allows you to edit massive amounts of files with just one click. Like the other search/replace functions, selecting this option will invoke a "Replace in Files" dialog where you can specify the parameters of your search and replace.

It is important for you to understand the replace in files command before you issue it because all changes are permanent and cannot be "undone". We therefore suggest doing a test before executing the command on the actual data, or making a backup of the actual data before running the replace in files.

In our example below, we have specified that all HTML files in our "htmlBackup" directory will be searched for "1,000,000", and all matches will be replaced with "2,000,000". We have selected the option to "List Changed Files," because we would like to know exactly where UltraEdit found a match and replaced it.

Once you've set these parameters to meet your specifications, you can press the "Replace All" button to begin the Replace in Files. As with the "Find in Files" function, depending on the amount of data, a "Replace in Files" over many files can take several minutes to complete.

Using Find, Replace, Find In Files, and Replace in Files

When the replace is complete the results summary is written to the output box. The summary tells you exactly where the replace occurred and how many times it occurred in each file.

According to our results summary (shown below), our string was replaced once in "home.html", twice in "index.html", and three times in "ultraedit.html". The last line is an overall summary that tells us the string was replaced six times in three different files.

Using Find, Replace, Find In Files, and Replace in Files

The additional options in the "Replace in Files" dialog, that were mentioned previously for the Find in Files description, perform the same function (as described above) in the Replace in Files.


Back to power tips index


Buy Now
Upgrade
Download

Get your solution today!

UE/UC

Add UltraCompare to your purchase/upgrade of UltraEdit and complete your file management solution.

Your bundle license runs on Windows, Mac, and Linux.

Working on a team?

UEStudio

Check out UEStudio - designed for those who collaborate!


"We won't mince words:
UltraEdit is outstanding..."

Application Screenshots

Feature maps

Road trip, anyone?

UE Mobile

Bundle UE Mobile with your UE upgrade and save 50%!


Take the UltraEdit tour