Forum Discussion

curious7's avatar
curious7
Copper Contributor
Feb 18, 2025
Solved

What REGEX can I use to detect a UPN being sent in Email/Shared Document in Onedrive/Sharepoint

I need to create a REGEX for a sensitive info type that will detect if a UPN is being sent in email or shared with external users in a document. I created a primary element with following for single...
  • luchete's avatar
    Feb 21, 2025

    Hello curious7,

    The regex you're using for detecting email addresses is too general and doesn't fully account for the context of replies with "<" and ">".

    To fix this, I recommend adjusting your regex so it’s more specific about excluding those reply formats. One way is to use lookahead and lookbehind assertions. Here's an approach:

    Try adding a condition to ensure the email is not preceded by "<" and not followed by ">". You can do something like this:

    (?<!<)\b\w+(\.\w+)?@\w+(\.\w+)+\b(?!>)

    This regex ensures that the email address is not directly preceded by "<" and not directly followed by ">". This should stop the unwanted matches from email replies.

    Additionally, ensure that your secondary element for domain checks correctly matches your intended domains without being too broad. This can help prevent false positives.

    Regards!

Resources