HandyFile Find And Replace Online Help Submit feedback on this topic   

HOWTO: Use Scenarios To Automate Work

We introduced scenarios in the HandyFile Find And Replace so that you can get rid of the monotonous operations that involve searching and replacing many different portions of text in multiple files. Let us consider an example of cleaning HTML files saved from within Microsoft Word.

We will want to:

There are much more Word dirt in the HTML but we shall limit our example to these searches.

We start by opening the Scenario editor by clicking the Advanced Search button and selecting Manage Scenarios from the menu.

In the Scenario dialog, create a new scenario by clicking the New button. Type the name of the new scenario, for example, Clean up Word HTML.

After the new scenario is created, start adding actions to it.

  1. Click the button Add Action and give it a name for the first action, for example: Remove comments.
  2. We shall need regular expressions to cover all comments in a file.
    So we check the Regular expressions option and type the following text in the Find what field:

    \<\!\-\-.#\-\-\>

    Here:

    • \<\!\-\- is the comment opening tag;
    • .# (any character + match 1or more times non-greedy) means "match all further text but stop before the next symbol in the expression (non-greedy)";
    • \-\-\> is the comment closing tag.

    Please note that you should escape all non-alphanumeric symbols when searching with regular expressions.

    As we want to remove comments, we leave the Replace with field blank.

  3. To delete SPAN tags, we create a new action and also use regular expressions but more complex for the Find what field:

    \<span\s#lang\=\w#\-\w#\s#style\=\'mso.#\'\>(.#)\<\/span\>

    Here:

    • #lang\=\w#\-\w# stands for the LANG attribute with the language abbreviation;
    • style\=\'mso.#\' matches any style attribute starting from any mso style attribute;
    • (.#) is the tag inner text that we must preserve.

    We replace the found text with the tag inner text:

    \1

    We shall omit operations on adding actions for being short.

  4. To delete tags <o:p>, we do not need regular expressions as they always have only one form:

    Find what: <o:p></o:p>

    Replace with: empty

  5. To clean the HTML tag, we need regular expressions again:

    Find what: \<HTML.#\>

    Replace with: <HTML>

    Please note that escapes are optional in the replace field.

  6. And lastly, we shall remove the Office [if] conditions.

    Find what: \<\!\[if\s.#\]\>(.#)\<\!\[endif\]\>

    Replace with: \1

    Please note that escapes are optional in the replace field.

We have now created a new scenario. Click the Save and Activate button. The Files and Text Tab will change to the Advanced mode displaying the scenario name.

Now do the common operations:

Note
Please do not forget that you can run the HFFR from the command line and specify the name of a scenario to activate by using the parameter /scn:"scenario_name"