Search code examples
emeditor

Emeditor to extract displayed strings for each line (maintaining the line order)


How can I use emeditor to find and extract regex strings but maintain the same lines +/- a delimiter?

The output I get when I try to extract displayed strings, extracts each matched string to a new line. But my goal is to extract these matches from each line (removing the values I dont want)

For example

Starting with:

dog cat food
prince dog food

I would like to end up with

dog food
prince food

Or

with a delimiter

dog, food
prince, food

But using Emeditor

  1. Cntr+F
  2. (\b\w+\b)$|^\w+ and then selecting Regular expressions and extract>display matched strings only

the ouput is

dog
food
prince
food

Can this be accomplished using EmEditor or through a macro?


Solution

  • Use the Filter toolbar instead of the Find dialog.

    1. In the Filter toolbar, click the Use Regular Expressions button, and enter a regular expression, for instance, ^\w+|\w+$, in the Filter drop-down list box.

    enter image description here

    1. Click the Extract All button in the Filter toolbar, then select Extract Options in the popup menu.

    enter image description here

    1. In the Filter Extract Options dialog box, select Extract all matched strings, and enter \t or , as a Delimiter. Click OK.

    2. Click the Extract All button again in the Filter toolbar, then select Extract Matched Strings in the popup menu.

    If you record this procedure to a macro, you will get a macro like this:

    document.Filter("^\\w+|\\w+$",0,eeFindReplaceRegExp,0,0,0,0,0);
    editor.ExecuteCommandByID(4084);  // Extract Matched Strings
    

    If you need to run this macro against many files in a folder, please see: Emeditor: run a macro for all file inside a folder?