How to Match Multiple Header Values with Exchange Online Transport Rule Regex
Question details
The user needs to create an Exchange Online transport rule exception using a regular expression that can simultaneously match multiple values (such as dmarc=pass and header.from=contoso.com) separated by line breaks in the Authentication-Results header.

- Product
- Microsoft Exchange Online
- Device & OS
- not provided
- Scenario
- Creating a bypass exception to an 'External Sender' warning rule for authorized third-party services (like MailChimp or CVENT) that send emails on the organization's behalf.
- Observed behavior
- Exchange transport rule regular expressions lack a simple 'AND' operator, making it difficult to match multiple specific string components that span across intervening text, whitespace, and line breaks.
Ensure you have Exchange Administrator permissions to access the Exchange Admin Center (EAC). It is highly recommended to test new mail flow rules by setting them to 'Test' mode before enforcing them organization-wide.
Use Advanced Regex Patterns for Intervening Header Content
Since Exchange regular expressions do not have a built-in 'AND' operator, you must use a pattern that explicitly accounts for wildcards, whitespace, and line breaks between the desired header values.
When matching the Authentication-Results header, you cannot simply write two conditions and assume they will apply to the same line. You must construct a regex that bridges the gap between your required strings.
A common approach is using the [\s\S]* syntax, which matches any character including line breaks, allowing you to catch both 'dmarc=pass' and 'header.from' regardless of what appears between them.
Log in to the Exchange Admin Center (EAC) and navigate to 'Mail flow' > 'Rules'.
Select your existing 'External Warning' transport rule and click the Edit (pencil) icon.
Under 'Except if', select 'A message header' > 'matches these text patterns'. Enter 'Authentication-Results' as the header name.
Input a regex pattern that bridges the two values, such as 'dmarc=pass[\s\S]*header\.from=contoso\.com' or 'header\.from=contoso\.com[\s\S]*dmarc=pass'. Save and test the rule.

Manage Approved Third-Party Senders via IP Addresses
If precise regex matching proves unreliable due to complex header formatting, manage approved third-party senders through centralized mail-flow IP controls instead.
Need a Reliable and Free Alternative for Your Daily Office Tasks?
While troubleshooting complex Microsoft Exchange configurations, managing your everyday documents shouldn't be a hassle. WPS Office is a lightweight, highly compatible productivity suite that supports all major Microsoft Office file formats, making it easy to create, edit, and share files without expensive subscription fees.
- 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install WPS Office: Run the downloaded installation file and follow the on-screen prompts to set up the software.
- 3. Open Your Files: Launch WPS Office and instantly open your existing Microsoft documents with perfect formatting preservation.

Frequently Asked Questions
Why doesn't the standard regex AND logic work in Exchange transport rules?
Exchange transport rules use a specific, restricted subset of regular expressions designed for performance. They do not support complex lookarounds or simple logical 'AND' operators. To match two strings in the same text block, you must explicitly pattern-match the spaces and characters (using syntax like [\s\S]*) between the two strings.
How can I safely test my Exchange transport rule before applying it?
In the Exchange Admin Center, you can set the rule's enforcement mode to 'Test without Policy Tips' or 'Test with Policy Tips'. This allows you to review message tracking logs to see if the rule is triggering correctly without actually modifying or blocking live emails.
What exactly is the Authentication-Results header?
The Authentication-Results header is stamped onto an email by the receiving mail server. It contains the evaluation results of standard email authentication protocols like SPF, DKIM, and DMARC, which are critical for verifying the sender's identity and preventing spoofing.




