Forum Discussion
What REGEX can I use to detect a UPN being sent in Email/Shared Document in Onedrive/Sharepoint
- 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!
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!