Multiline find and replace

Note: As of UltraEdit v14.00 and UEStudio v06.50, multiline find and replace is natively supported. Simply press Ctrl + Enter to insert a new line into the find or replace dialogs.
A powerful feature of UltraEdit and UEStudio is their wide range of find/replace features. You can find a string of text in a file, in multiple files, all open files, project files, throughout a directory and its sub-directories, and more. Not only can you perform a find but also a replace. Oh, and did we mention it supports regular expressions? But that’s another subject… (learn about Perl regular expressions)

What happens if the text you need to find/replace spans multiple lines? No problem… You’ve come to the right place.

How to use multi-line variables to remove unwanted line breaks from text


Step 1: Know the variables

UltraEdit includes special characters that you can use to represent nonprintable characters like new lines, tabs, etc. For example, use “^p” in a find or replace dialog to represent the new line character (CR/LF).

You can also use the contents of the clipboard or selected text in a search or replace string with “^c” and “^s” respectively.

UltraEdit and UEStudio support the following variables in the find and replace dialogs:

Symbol Function
^^ searches for a “^” character
^s searches for selected (highlighted) text when a macro is running
^c searches for the contents of the clipboard when a macro is running
^b matches a page break
^p matches a newline (CR/LF) – DOS files
^r matches a newline (CR only) – Mac (legacy) files
^n matches a newline (LF only) – Unix files
^t matches a tab character

Additional information regarding find / replace and find in files / replace in files is available in UltraEdit help documentation.

Step 2: Do the replace

Let’s say you have a paragraph of text containing hard lines breaks which you’d like to remove. This kind of thing happens quite often when copying / pasting text, for example, from a browser to an HTML file.

Select the text which you would like replaced. Press Ctrl + R to open the replace dialog.

In more recent versions of UltraEdit and UEStudio, with more than one line selected, the Replace dialog will automatically set “In” to “Selected text” and leave the “Find what” field empty. If you’re not using one of these newer versions (or you have this setting turned off), you’ll need to manually make these adjustments in the Replace dialog.

For “Find what,” enter “^p” to represent the new line characters. Enter a single space into “Replace with” – this will ensure the words separated by the new lines aren’t jammed together.

Click Replace all. The line breaks are removed, and all text is now on a single line.