Sign in
    Shared Email Templates

    Insert text using a regular expression

    The RegexMatch macro in Shared Email Templates searches an Outlook email for text that matches a regular expression, or regex. Depending on whether a match is found, the macro inserts one of two predefined text values. To add the macro to your email template, follow the steps below.

    1. Start creating or editing a template.

    2. Place the cursor where you want to insert the predefined text.

    3. On the template editor toolbar, select the The Insert macro icon. Insert macro button.

    4. Select RegexMatch.

    5. In the Regex match dialog:

      • Select the fields where the macro should look for a match.
      • Enter a regex.
      • If you want to make the search case insensitive, select the corresponding checkbox.
      • Enter the value if matched (the text that will appear in your email message if a regex match is found).
      • Enter the value if not matched (the text that will appear in your email message if a regex match is not found).

      For example, let’s say you want the add-in to insert Thank you for your order ID. when the subject of the email you’re replying to contains an order ID. When the subject doesn’t contain an order ID, you want the add-in to insert Thank you for contacting us. instead. Here’s what to do:

      • Under Fields, select subject.
      • Under Regex, enter a regular expression that matches the order ID pattern. For example, use \b[A-Z]{2}[0-9]{5}\b to match order IDs that start with two uppercase letters followed by five digits, such as DE12345.
      • Under Value if matched, enter Thank you for your order ID.
      • Under Value if not matched, enter Thank you for contacting us.

      When you’re ready, select OK.

      Set up the RegexMatch macro.
    6. Save the template.

    When you insert the template into an Outlook reply, the macro searches the selected fields for a regular expression match. If it finds a match, it inserts one predefined text value; if it doesn’t, it inserts the other.

    An Outlook email with one of the two predefined text phrases inserted automatically.

    See also #