Exchange Connection Problems

How to Match Multiple Header Values with Exchange Online Transport Rule Regex

Ayan MasoodAyan Masood Nov 2, 2026 871 views

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.

How to Match Multiple Header Values with Exchange Online Transport Rule Regex
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.
Before you start

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.

Solution 1Recommended

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.

1
Access Mail Flow Rules

Log in to the Exchange Admin Center (EAC) and navigate to 'Mail flow' > 'Rules'.

2
Edit the External Warning Rule

Select your existing 'External Warning' transport rule and click the Edit (pencil) icon.

3
Add a Regex Exception

Under 'Except if', select 'A message header' > 'matches these text patterns'. Enter 'Authentication-Results' as the header name.

4
Define the Regex Pattern

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.

Use Advanced Regex Patterns for Intervening Header Content
Check Header Order: Because regex processes sequentially, you may need to add two exception patterns if you are unsure whether 'dmarc=pass' or 'header.from' appears first in the actual mail header.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install WPS Office: Run the downloaded installation file and follow the on-screen prompts to set up the software.
  3. 3. Open Your Files: Launch WPS Office and instantly open your existing Microsoft documents with perfect formatting preservation.
Fully compatible with Microsoft Word, Excel, and PowerPoint file formats (.docx, .xlsx, .pptx).Lightweight design that installs quickly and runs smoothly on Windows, Mac, Linux, iOS, and Android.Includes built-in PDF editing tools for comprehensive document management and conversions.Features a familiar, tabbed user interface ensuring seamless migration from Microsoft Office.
microsoft office alternative - wps office

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.