Microsoft Outlook Add-In: Contextual Regex for Links

joostwmd 5 Reputation points
2024-12-15T19:52:54.6366667+00:00

I want to develop a Microsoft Outlook add-in that highlights links in Emails. I found this example for a add in that highlights order numbers and displays a popup when clicking on it. The Code "responsible" for that is this regex in the manifest:

<Rule xsi:type="RuleCollection" Mode="And">

<Rule xsi:type="ItemIs" ItemType="Message" />

<Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="OrderNumber" RegExValue="CO-\d{9}" PropertyName="BodyAsPlaintext"/>

</Rule>

I basically want the same for any link in an email. I thought I could just use a regex for a link, bit somehow it is not working. Here is my current code:

<Rule xsi:type="RuleCollection" Mode="And">

<Rule xsi:type="ItemIs" ItemType="Message" />

<Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="Link" RegExValue="(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})" PropertyName="BodyAsPlaintext"/>

</Rule>

My goal is to prevent the default behaviour which is opening the link and displaying the popup instead, like in the example:

Screenshot 2024-12-15 at 20.52.04

Has anyone figured this out?

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,432 questions
Outlook
Outlook
A family of Microsoft email and calendar products.
4,280 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,129 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Digvijay Chauhan 1 Reputation point
    2024-12-15T23:06:10.4933333+00:00

    Hi joostwmd,

    Could you get the example to run locally before you started to play around with your regular expression?

    It is actually two parts :

    In the file contoso-order-number-manifest.xml line 52-56

    <Rule xsi:type="RuleCollection" Mode="And">
        <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
        <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="9Digits" RegExValue="\d{9}" 			PropertyName="BodyAsPlaintext"/>  
    </Rule>   
    <DisableEntityHighlighting>false</DisableEntityHighlighting>
    
    

    Notice 9Digits - it must match so it goes to second one: line 74-77

     <Rule xsi:type="RuleCollection" Mode="And">
                    <Rule xsi:type="ItemIs" ItemType="Message" />
                    <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="OrderNumber" RegExValue="CO-\d{9}" PropertyName="BodyAsPlaintext"/>              
    </Rule>
    
    

    So i guess if you just put the rule either in top block or make it pass on to second rule it should work!

    Hope that helps!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.