How to find and replace multi-line text

Posted by HTML-Kit Support January 27, 2012
 

So you have a block of text that you want to replace and it has more than one line.

HTML-Kit Tools : Finding and replacing multi-line text in the current document

Let's start with the quick solution. If you're using HTML-Kit Tools, one of the options on "Edit > Replace" menu is a dialog for finding and replacing multi-line text. Simply paste or enter the text you're looking for and start replacing.

HTML-Kit Tools : Finding and replacing multi-line text in multiple files

Multi-line support is also in batch find and batch replace functions in HTML-Kit Tools:

  1. Open a project from "File > Projects" menu
  2. Inside the project window, select a folder where you'd like to start searching
  3. Right click (the selected folder), and pick "Batch Actions > Find in Files" from the pop-up menu
  4. You'll see a find field that allows for multiple lines

That's HTML-Kit Tools, which had the luxury of following HTML-Kit 292 and learning the few things along the way.

HTML-Kit 292 : Finding and replacing multi-line text in the current document

Finding (and replacing) mult-line text is a little tricky in HTML-Kit 292, but not impossible.

To find a block of text in the current document:

  1. Press Ctrl+F
  2. Click "..." next to the "Find what" field
  3. Paste or enter multi-line text, and click OK
  4. Click "Find Next" to start searching

That wasn't too bad, was it?

HTML-Kit 292 : Finding multi-line text in multiple files

Let's try searching for a block of text, with many lines, in multiple files and folders:

  1. If you haven't already, install Ciaran's excellent cmBatchFind plugin. This adds batch search capability to HTML-Kit 292.
  2. Select "Actions > Batch Actions > Find Text" from the main menu

As you see, the "Search Expression" field only accepts a single line of text. It is however possible to convert a block of text into a single-line regex expression and use that as the search expression. Or, you can use the following multi-line text to single-line regex converter:

Multi-line text to find:

When working with the cmBatchFind plugin:

  1. Copy the single-line regular expression you've generated for the find text, and paste it in "Search Expression" field.
  2. Add "r" (without quotes) to "Options" field.
  3. Finally, click "Start" to begin batch search.

HTML-Kit 292 : Replacing multi-line text in multiple files

The Search Expression generated above also works with cmBatchReplace plugin. However, the "Replace With" text has to be formatted to include new lines and escape "\" characters. Here's a converter for generating a single-line "Replace With" text:

Multi-line text to replace with:

When working with the cmBatchReplace plugin:

  1. Copy the single-line regular expression you've generated for the find text, and paste it in "Search Expression" field.
  2. Copy the single-line replace text you've generated, and paste it in "Replace With" field.
  3. Add "r" (without quotes) to "Options" field.
  4. Finally, click "Start" to begin batch replace.
comments powered by Disqus