Using Keywords and Regular Expressions
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 11 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Implementing Information Protection: Mastering Keywords and Regular Expressions in Microsoft Purview
Introduction: The Foundation of Data Governance
In the modern digital workplace, organizations generate, store, and share massive volumes of data every single day. From internal project documentation to sensitive customer financial records, the sheer scale of information makes manual oversight impossible. Microsoft Purview serves as the central hub for managing this data, providing the tools necessary to classify, protect, and manage the lifecycle of information. At the heart of these capabilities lies the ability to identify specific types of data, which is primarily achieved through Sensitive Information Types (SITs).
Sensitive Information Types act as the "eyes" of your data governance strategy. Without them, the system cannot distinguish between a public marketing brochure and a confidential legal contract. By utilizing keywords and regular expressions (Regex), you provide the logic necessary for the system to scan, identify, and categorize data automatically. This lesson explores how to harness these two fundamental building blocks to build a precise, effective, and reliable compliance framework that keeps your organization's data secure while minimizing administrative overhead.
Not read yet
Understanding Sensitive Information Types (SITs)
Before diving into the technical implementation of keywords and regular expressions, it is essential to understand where these elements fit within the broader Microsoft Purview architecture. A Sensitive Information Type is a policy-based detector that looks for specific patterns in your data—such as credit card numbers, social security numbers, or custom project code names.
When you configure a SIT, you are essentially creating a set of rules that the scanning engine follows. These rules are defined by "elements" that the engine looks for. These elements can include:
- Keywords: A list of specific words or phrases that indicate the presence of sensitive content.
- Regular Expressions (Regex): Complex string patterns used to identify data that follows a specific format (like a sequence of numbers and dashes).
- Supporting Evidence: Additional criteria, such as proximity requirements or confidence levels, that confirm a match.
By combining these elements, you move away from simple "find-all" searches and toward context-aware intelligence. This reduces false positives—where the system flags harmless documents—and false negatives—where the system misses genuinely sensitive data.
Callout: Keyword vs. Pattern-Based Detection It is vital to distinguish between keyword-based detection and pattern-based detection. Keywords are static; they look for exact matches of defined terms. Regex, on the other hand, is dynamic; it looks for the structure of data regardless of the specific content. A robust compliance strategy rarely relies on just one; it uses keywords to narrow the scope and regex to validate the format.
Not read yet
Implementing Keywords for Data Identification
Keywords are the most straightforward way to identify sensitive data. If your organization uses specific terminology, project titles, or internal codenames, keywords are your first line of defense.
Best Practices for Keyword Management
When working with keywords, the quality of your list is directly proportional to the accuracy of your detection. If your keyword list is too broad, you will overwhelm your compliance team with noise. If it is too narrow, you will miss critical information.
- Use Keyword Dictionaries: Instead of hard-coding lists into your rules, use Keyword Dictionaries. These are centralized lists that can be updated independently of your sensitive information rules.
- Contextualize with Proximity: Always pair keywords with proximity requirements. For example, if you are looking for "Project Alpha," require that the word "Confidential" or "Restricted" appears within 300 characters.
- Avoid Overlap: Ensure your keywords are unique enough to avoid triggering on common vocabulary. Using a project codename like "Red" is a bad idea because it is a common English word; "ProjectRed2024" is much safer.
Step-by-Step: Creating a Keyword Dictionary
- Navigate to the Microsoft Purview compliance portal.
- Go to Data classification and then Sensitive information types.
- Select the Keyword dictionaries tab.
- Click Create keyword dictionary, provide a name, and upload a CSV or text file containing your keywords.
- Once saved, you can reference this dictionary in any custom Sensitive Information Type by selecting it as a "Keyword" element.
Tip: Keep your keyword lists updated. As projects end or new initiatives begin, audit your dictionaries to ensure they still reflect the current state of your organization's data.
Not read yet
Leveraging Regular Expressions (Regex) for Precision
Regular expressions are the power tools of data identification. While keywords are excellent for finding specific names or terms, they are useless for identifying data formats like credit card numbers, passport numbers, or internal ID strings. A regex provides a pattern that the scanner uses to validate if a string of text matches the structure you are looking for.
Understanding the Regex Syntax
Regex can be intimidating at first, but it follows a logical structure. Here are the core components you will use most often in Purview:
\d: Matches any single digit (0-9).\w: Matches any alphanumeric character (word character).[A-Z]: Matches any uppercase letter.{n}: Specifies that the previous element must occur exactly n times.+: Specifies that the previous element must occur one or more times.?: Specifies that the previous element is optional.
Practical Example: Identifying an Internal Employee ID
Suppose your organization uses an Employee ID format that consists of two uppercase letters, followed by a hyphen, and then five digits (e.g., AB-12345).
The regex for this would be: [A-Z]{2}-\d{5}.
[A-Z]{2}: Looks for exactly two uppercase letters.-: Looks for the literal hyphen character.\d{5}: Looks for exactly five digits.
If you simply searched for the digits, you might flag phone numbers or dates. By using this regex, you ensure you are only flagging data that fits your specific internal ID format.
Warning: Be careful with performance. Extremely complex regular expressions can cause significant processing delays when scanning large datasets. Always test your regex against a sample set of data before deploying it to your entire tenant.
Not read yet
Advanced Techniques: Combining Keywords and Regex
The most effective compliance rules combine both keywords and regex. This is known as "Evidence-Based Matching." You use the regex to find the potential sensitive item, and you use keywords to confirm that the document is indeed sensitive.
Scenario: Protecting Project Financials
Imagine you want to identify documents containing financial figures related to "Project Omega."
- The Regex: You define a regex to look for currency formats like
$1,000,000. - The Keyword: You reference a keyword dictionary containing "Project Omega," "Financials," and "Budget."
- The Logic: You configure the rule so that it only triggers a match if the regex (the money) appears within 200 characters of one of the keywords.
This prevents the system from flagging a generic public document that happens to mention a dollar amount, while still catching the sensitive financial report for "Project Omega."
Implementing Logic in the Purview Portal
When editing a Sensitive Information Type in the Purview portal, you can define "Elements." You can add multiple elements and then define the relationship between them:
- All elements must be present: The rule only triggers if both the keyword and the regex match.
- At least one element must be present: The rule triggers if either matches (useful for broad searches).
- Specific proximity: You define how close the elements must be to each other in the document.
Not read yet
Best Practices for Information Protection
Implementing these controls is not a "set it and forget it" task. It requires a disciplined approach to maintenance and oversight.
1. The "Test and Tune" Cycle
Always start by deploying your new Sensitive Information Type in "Test" or "Audit" mode. This allows you to see what would have been flagged without actually applying any protection or labels to the files. Use the reports generated during this phase to identify false positives and adjust your regex or keyword lists accordingly.
2. Document Your Patterns
Maintain a central document or repository that tracks why certain regex patterns were created and what they are intended to catch. Over time, as team members leave or roles change, institutional knowledge about why a specific rule exists can be lost. Clear documentation ensures that future administrators know exactly how to modify or retire rules.
3. Use Confidence Levels
Microsoft Purview allows you to set confidence levels (Low, Medium, High). A regex that is very specific (like a 16-digit credit card number with a checksum validation) can be set to "High" confidence. A keyword-only match might be set to "Low" confidence. Use these levels to automate actions; for example, you might automatically encrypt files with "High" confidence matches, but only notify the owner for "Low" confidence matches.
4. Leverage Built-in SITs First
Before creating your own, explore the hundreds of built-in Sensitive Information Types provided by Microsoft. These cover common international standards like GDPR, HIPAA, and various national ID formats. Only create custom types when the built-in ones do not meet your specific organizational needs.
Not read yet
Common Pitfalls and How to Avoid Them
Even experienced administrators run into issues when implementing keywords and regex. Here are the most common mistakes and how to navigate them.
Pitfall 1: The "Greedy" Regex
A common mistake is writing a regex that is too broad. For example, using \d+ to find IDs will match any number of any length, including page numbers, dates, and random statistics.
- Fix: Always constrain your regex. If you know an ID is exactly 10 digits, use
\d{10}instead of\d+. If it starts with a specific prefix, include that prefix in the regex.
Pitfall 2: Ignoring Case Sensitivity
By default, some systems treat "Project" and "project" differently. While Microsoft Purview is generally case-insensitive for keywords, it is crucial to be explicit in your regex.
- Fix: Use the case-insensitive flag if necessary, or explicitly define character ranges like
[a-zA-Z].
Pitfall 3: Failing to Account for Variations
Data rarely follows a perfect format. Users might type a credit card number as 1234-5678-9012-3456, 1234 5678 9012 3456, or 1234567890123456.
- Fix: Write your regex to be flexible. Use the
?operator for optional characters. For example,\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}will match all three variations mentioned above.
Pitfall 4: Performance Overload
Applying a highly complex, computationally expensive regex to every single file in a massive SharePoint site can lead to latency.
- Fix: Use "Keyword" as a primary filter. If the document does not contain the word "Confidential," the system won't even bother running the expensive regex. This "pre-filtering" technique is essential for large-scale environments.
Not read yet
Quick Reference Table: Regex Operators
| Operator | Description | Example |
|---|---|---|
\d |
Any digit (0-9) | \d{3} matches 123 |
\w |
Any alphanumeric character | \w{5} matches ABC12 |
. |
Any character except newline | A.C matches ABC, ADC, A1C |
^ |
Start of a string | ^ID matches IDs at the beginning |
$ |
End of a string | End$ matches words at the end |
* |
Zero or more occurrences | a* matches "", "a", "aa" |
+ |
One or more occurrences | a+ matches "a", "aa" |
? |
Optional element | colou?r matches color and colour |
Practical Scenario: Creating a Custom SIT for Project Codes
Let's walk through the creation of a custom Sensitive Information Type for a fictitious company, "Contoso," which uses a unique project code format: CON-XXXX-YY (where X is a digit and Y is a letter).
Step 1: Define the Regex
The pattern needs to look for:
- "CON-" (Fixed prefix)
- Four digits (
\d{4}) - A hyphen (
-) - Two letters (
[a-zA-Z]{2})
The resulting regex: CON-\d{4}-[a-zA-Z]{2}
Step 2: Define the Keyword
We want to ensure this only flags documents that are actually related to the "Project" initiative. We will add a keyword dictionary called "ContosoProjects" containing terms like "Project Definition," "Internal Strategy," and "Budget Proposal."
Step 3: Configure the Rule
- In the Purview Compliance portal, go to Sensitive information types.
- Create a new SIT named "Contoso Project Code."
- Add an element: Regular Expression. Paste
CON-\d{4}-[a-zA-Z]{2}. - Add an element: Keyword Dictionary. Select "ContosoProjects."
- Set the logic to "All elements must be present."
- Set the Proximity to 300 characters.
- Save and test by uploading a sample document that contains both the code and the keyword.
Not read yet
Maintaining Your Compliance Framework
The landscape of your data is constantly shifting. New regulations, new business units, and new types of documents mean that your Purview configuration must be dynamic. Establish a quarterly review process where you:
- Audit Detection Rates: Are there high volumes of false positives? If so, tighten your regex or proximity requirements.
- Review Missed Data: If your team reports that certain sensitive files were not protected, analyze those files to see why they didn't trigger the rule. Was it a formatting quirk? A missing keyword?
- Update Dictionaries: Add new project names or terminologies to your keyword dictionaries to ensure they stay relevant.
- Retire Old Rules: If a project has concluded, disable or remove the associated rules to keep the system clean and performant.
Note: The "Test" mode in Purview is your best friend. Never deploy a new rule directly into "Production" without first verifying its behavior on a subset of your data. This simple step prevents major disruptions to user workflows.
Not read yet
Integrating with Data Lifecycle Management
Once you have identified your sensitive data, the next step is acting upon it. This is where Data Lifecycle Management (DLM) and Information Protection labels come into play.
- Apply Labels Automatically: Use your custom SITs to automatically apply "Confidential" sensitivity labels to documents. This ensures that even if a user forgets to label a file, the system handles it based on the content.
- Retention Policies: If your SIT identifies a legal document, you can trigger a retention policy that keeps that file for seven years, ensuring you meet regulatory requirements without manual intervention.
- Encryption: For high-confidence matches, you can automatically apply encryption, ensuring that only authorized users can open the document, regardless of where it is stored or shared.
The Human Element: Training and Communication
Technology is only one part of the equation. Your employees play a massive role in data security. If they do not understand why these rules exist, they may find ways to bypass them.
- Explain the "Why": Communicate to staff that these rules are designed to protect them and the company from data breaches.
- Provide Feedback Loops: If a user gets a "Policy Tip" or a warning, give them a way to report if they believe the system was wrong. This feedback is invaluable for refining your regex and keyword rules.
- Encourage Responsible Handling: Use the compliance tools to educate users. When a file is flagged as sensitive, the system can display a message explaining the proper handling procedures.
Not read yet
Summary of Key Takeaways
Managing compliance through keywords and regular expressions is a precise, technical, yet highly rewarding aspect of data governance. By following these principles, you ensure your organization’s data remains secure and compliant with both internal policies and external regulations.
- Keywords provide context: They are the best way to anchor your detection rules to specific business terminology, projects, or departments.
- Regex provides precision: They are essential for identifying structured data, such as account numbers, IDs, and codes that follow a predictable format.
- Proximity is critical: Never rely on a keyword or a regex in isolation. Combining them with proximity requirements is the most effective way to eliminate false positives.
- Performance matters: Always consider the computational cost of your regex. Use keywords as a "filter" to ensure your regex only runs when necessary.
- Testing is mandatory: Use the audit/test modes in Microsoft Purview to validate your rules before they have a real-world impact on your users.
- Documentation is key: Keep a record of why your rules exist and what they are designed to catch to ensure long-term maintainability.
- Lifecycle integration: Remember that identifying data is only the first step. Integrate your SITs with sensitivity labels and retention policies to fully manage the lifecycle of your information.
By mastering these tools, you move from a reactive security posture to a proactive, automated, and highly reliable data governance framework. The effort you invest in crafting these rules today will pay dividends in the form of reduced risk and increased operational efficiency tomorrow.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
- Creating a Microsoft 365 Tenant
- Creating a Microsoft 365 Tenant Quiz5q
- Implementing and Managing Domains
- Implementing and Managing Domains Quiz5q
- Configuring Organization Settings
- Configuring Organization Settings Quiz5q
- Monitoring Microsoft 365 Service Health
- Monitoring Microsoft 365 Service Health Quiz5q
- Configuring Network Connectivity Insights
- Configuring Network Connectivity Insights Quiz5q
- Managing Software Updates in Microsoft 365
- Managing Software Updates in Microsoft 365 Quiz5q
- Monitoring Microsoft 365 Adoption and Usage
- Monitoring Microsoft 365 Adoption and Usage Quiz5q
- Configuring Microsoft 365 Backup
- Configuring Microsoft 365 Backup Quiz5q
- Creating and Managing Users in Microsoft Entra ID
- Creating and Managing Users in Microsoft Entra ID Quiz5q
- Managing External Users and Guest Access
- Managing External Users and Guest Access Quiz5q
- Creating and Managing Contacts
- Creating and Managing Contacts Quiz5q
- Creating and Managing Microsoft 365 Groups
- Creating and Managing Microsoft 365 Groups Quiz5q
- Managing Shared Mailboxes
- Managing Shared Mailboxes Quiz5q
- Managing Microsoft 365 Licenses
- Managing Microsoft 365 Licenses Quiz5q
- Performing Bulk User Management with PowerShell
- Performing Bulk User Management with PowerShell Quiz5q
- Implementing Group-Based Licensing
- Implementing Group-Based Licensing Quiz5q
- Implementing Roles in Microsoft 365
- Implementing Roles in Microsoft 365 Quiz5q
- Managing Microsoft Entra ID Roles
- Managing Microsoft Entra ID Roles Quiz5q
- Managing Permissions for Microsoft Defender XDR
- Managing Permissions for Microsoft Defender XDR Quiz5q
- Managing Delegation with Administrative Units
- Managing Delegation with Administrative Units Quiz5q
- Managing Roles with Privileged Identity Management
- Managing Roles with Privileged Identity Management Quiz5q
- Managing Microsoft Purview Permissions
- Managing Microsoft Purview Permissions Quiz5q
- Preparing for Identity Synchronization
- Preparing for Identity Synchronization Quiz5q
- Using IdFix for Directory Cleanup
- Using IdFix for Directory Cleanup Quiz5q
- Implementing Microsoft Entra Connect Sync
- Implementing Microsoft Entra Connect Sync Quiz5q
- Implementing Microsoft Entra Cloud Sync
- Implementing Microsoft Entra Cloud Sync Quiz5q
- Monitoring with Microsoft Entra Connect Health
- Monitoring with Microsoft Entra Connect Health Quiz5q
- Troubleshooting Synchronization Issues
- Troubleshooting Synchronization Issues Quiz5q
- Implementing Authentication Methods
- Implementing Authentication Methods Quiz5q
- Implementing Self-Service Password Reset
- Implementing Self-Service Password Reset Quiz5q
- Implementing Microsoft Entra Password Protection
- Implementing Microsoft Entra Password Protection Quiz5q
- Investigating Authentication Issues
- Investigating Authentication Issues Quiz5q
- Configuring Passwordless Authentication
- Configuring Passwordless Authentication Quiz5q
- Planning for Identity Protection
- Planning for Identity Protection Quiz5q
- Implementing Microsoft Entra Identity Protection
- Implementing Microsoft Entra Identity Protection Quiz5q
- Planning Conditional Access Policies
- Planning Conditional Access Policies Quiz5q
- Implementing Conditional Access Policies
- Implementing Conditional Access Policies Quiz5q
- Implementing Multifactor Authentication
- Implementing Multifactor Authentication Quiz5q
- Configuring Named Locations
- Configuring Named Locations Quiz5q
- Understanding Microsoft Security Exposure Management
- Understanding Microsoft Security Exposure Management Quiz5q
- Managing Microsoft Secure Score
- Managing Microsoft Secure Score Quiz5q
- Reviewing and Responding to Incidents
- Reviewing and Responding to Incidents Quiz5q
- Using Advanced Hunting in Defender XDR
- Using Advanced Hunting in Defender XDR Quiz5q
- Reviewing Defender XDR Reports
- Reviewing Defender XDR Reports Quiz5q
- Using Microsoft Defender Threat Intelligence
- Using Microsoft Defender Threat Intelligence Quiz5q
- Configuring Custom Detection Rules
- Configuring Custom Detection Rules Quiz5q
- Implementing Threat Policies in Defender for Office 365
- Implementing Threat Policies in Defender for Office 365 Quiz5q
- Configuring Alert Policies
- Configuring Alert Policies Quiz5q
- Investigating Email and Collaboration Threats
- Investigating Email and Collaboration Threats Quiz5q
- Managing Attack Simulation Training
- Managing Attack Simulation Training Quiz5q
- Managing Restricted Entities
- Managing Restricted Entities Quiz5q
- Onboarding Devices to Defender for Endpoint
- Onboarding Devices to Defender for Endpoint Quiz5q
- Configuring Endpoint Settings
- Configuring Endpoint Settings Quiz5q
- Using Vulnerability Management Dashboard
- Using Vulnerability Management Dashboard Quiz5q
- Responding to Endpoint Vulnerabilities
- Responding to Endpoint Vulnerabilities Quiz5q
- Managing Automated Investigation and Remediation
- Managing Automated Investigation and Remediation Quiz5q
- Configuring App Connector for Microsoft 365
- Configuring App Connector for Microsoft 365 Quiz5q
- Configuring Cloud Apps Policies
- Configuring Cloud Apps Policies Quiz5q
- Interpreting Activity Logs
- Interpreting Activity Logs Quiz5q
- Configuring Cloud App Discovery
- Configuring Cloud App Discovery Quiz5q
- Responding to Cloud App Discovery Issues
- Responding to Cloud App Discovery Issues Quiz5q
- Implementing Sensitive Information Types
- Implementing Sensitive Information Types Quiz5q
- Using Keywords and Regular Expressions
- Using Keywords and Regular Expressions Quiz5q
- Implementing Retention Labels and Policies
- Implementing Retention Labels and Policies Quiz5q
- Implementing Sensitivity Labels and Policies
- Implementing Sensitivity Labels and Policies Quiz5q
- Monitoring Label Usage with Content Explorer
- Monitoring Label Usage with Content Explorer Quiz5q
- Using Activity Explorer and Label Reports
- Using Activity Explorer and Label Reports Quiz5q
- Configuring Auto-Labeling Policies
- Configuring Auto-Labeling Policies Quiz5q
- Configuring DLP Policies for Exchange Online
- Configuring DLP Policies for Exchange Online Quiz5q
- Configuring DLP for SharePoint and OneDrive
- Configuring DLP for SharePoint and OneDrive Quiz5q
- Configuring DLP for Teams and Power BI
- Configuring DLP for Teams and Power BI Quiz5q
- Configuring DLP for Microsoft 365 Copilot
- Configuring DLP for Microsoft 365 Copilot Quiz5q
- Configuring Endpoint DLP
- Configuring Endpoint DLP Quiz5q
- Reviewing DLP Alerts and Events
- Reviewing DLP Alerts and Events Quiz5q
- Responding to DLP Reports
- Responding to DLP Reports Quiz5q
Spend your points to unlock exam-style practice questions
Spend points to unlock MS-102 exam-style practice questions.
Practice for MS-102