emeditor

Batch replace linearly with Linked File (Emeditor)


I am trying to run a linear replace with a linked file in Emeditor. The desired result is to change the phrases to wikilinks, starting from longer matches, and then serially to shorter matches:

  1. this is a phrase → [[this is a phrase]]
  2. is a phrase → [[is a phrase]]
  3. phrase → [[phrase]]

So if Line [1] is replaced, when running line [3] the originally longer phrase will not be affected. For example the output will not be [[this is a [[phrase]]]]

Now, I made sure in the replacements file longer lines are higher and tested with both Bulk and Batch Replace, but failed to get the desired result (instead [[phrase]] instances were linked at word level)

The test files I use can be downloaded here


Solution

  • I hope I understand the task correctly.

    The test phrase should be placed in double square brackets.

    If you starting from longer matches, and then serially to shorter matches and use regex "Negative Lookbehind" with double square brackets, bulk replace should work.

    (?<!\[\[)

    It will only replace phrase without double square brackets in front. For higher accuracy, it can also be additionally tested below.

    Please let me know if i have understood your enter image description hereproblem correctly and if my suggestion helps

    As can be read in the help, "This is similar to Import, but a linked file only contains find and replace strings". The situation is different in the import file, where regex can be used (see screenshot).

    (Instead of the import file, I have inserted the screenshot here, as I can't upload a file.)

    https://www.emeditor.org/en/dlg/replace_in_files/index.html

    My suggestion is to prepare the replacement file as an import file, so regex can be used.

    enter image description here