locked
What is the correct regular expression to use in a transport rule to match any non-empty string? RRS feed

  • Question

  • Hello,

    I wish to use transport rules to put a signature onto any outgoing e-mail. Within these signatures I use AD attributes like %%Title%%. There are some employees which have no Title attribute set, so I wish to skip the rule inserting this attribute.

    My thought was to check the title attribute for being not empty. The transport rule I create is as follows:

    New-TransportRule "Signature - Title part" -ApplyHtmlDisclaimerLocation Append -ApplyHtmlDisclaimerText "%%Title%%<br>" -SenderADAttributeMatchesPatterns "Title:(\s|\S)(\s|\S)*"

    Running this command on the Exchange Online server returns with an error saying the pattern is invalid. To my understanding this pattern is perfectly valid.

    What is wrong with the pattern I use? Is there any other way to check for an empty attribute?

    Thanks in advance!

    Best regards, Daniel

    Monday, December 11, 2017 12:22 AM

Answers

  • Hi Daniel,

    Try using "\D" or "\S|\D" instead:

    New-TransportRule "Signature - Title part" -ApplyHtmlDisclaimerLocation Append -ApplyHtmlDisclaimerText "%%Title%%" -SenderADAttributeMatchesPatterns "Title:\D"

    As below:


    Best Regards,

    Niko Cheng


    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    • Marked as answer by Daniel Höppe Monday, December 11, 2017 10:48 AM
    Monday, December 11, 2017 8:43 AM

All replies

  • Hi Daniel,

    If you want to match any non-empty string, just use "\S" without "*":

    New-TransportRule "Signature - Title part" -ApplyHtmlDisclaimerLocation Append -ApplyHtmlDisclaimerText "%%Title%%" -SenderADAttributeMatchesPatterns "Title:\S"


    Best Regards,

    Niko Cheng


    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Monday, December 11, 2017 7:46 AM
  • Hello Niko,

    using the pattern you supplied it returns to me with an error saying "The pattern you specified contains prohibited leading or trailing regex characters.".

    Best Regards, Daniel

    Monday, December 11, 2017 8:25 AM
  • Hi Daniel,

    Try using "\D" or "\S|\D" instead:

    New-TransportRule "Signature - Title part" -ApplyHtmlDisclaimerLocation Append -ApplyHtmlDisclaimerText "%%Title%%" -SenderADAttributeMatchesPatterns "Title:\D"

    As below:


    Best Regards,

    Niko Cheng


    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    • Marked as answer by Daniel Höppe Monday, December 11, 2017 10:48 AM
    Monday, December 11, 2017 8:43 AM