-1

Thanks for your help in advanced. I have been trying to get this figured and out and some testing.... I am new to regex....

Office 365 is matching a credit card number pattern to a gift card. The gift card doesn't match any bank or company patterns and while 16 digits, they don't add up to the LUH test either of being divisible by 70 and =1.

Request 1: For testing purposes, I want to allow a specific gift card number (9050991566549878 or 9050-9915-6654-9878) through the filter. That way I can test with a specific gift card number. In Office 365 I was going to say "Except if the subject or body matches patterns: enter the regex expression here"

Request 2: I want to make a modification to my DLP rule that will allow gift cards that starts with the numbers 9040 (or any other four digit code for that matter and is 16 digits in length, not including the - in between (if the user enters them)). I have been struggling to write this as I see every other combination. In Office 365 I was going to say "Except if the subject or body matches patterns: enter the regex expression here"

THANK YOU!

Ryan B
  • 1

1 Answers1

0

Normally, I would use a regex like (\d{4}-?){4} to capture four digits followed by an optional hyphen repeated four times. However, lazy googling leads me to believe that Office 365 implements a much simpler form of regular expressions that don't include some of those characters. I think an Office 365 friendly version of the above regex that should work for you is:

\d\d\d\d(-|)\d\d\d\d(-|)\d\d\d\d(-|)\d\d\d\d

This amounts to a very verbose way of saying "gimme 4 digits, maybe a hyphen, 4 more digits, maybe a hyphen, 4 more digits, maybe a hyphen, 4 more digits.

ian
  • 94
  • 1
  • 6
  • 1
    Thanks, Ian - how do you think we could add it for specific numbers? Or perhaps an expression that says that we ignore anything that starts with a 1 or 2 and is in a 16 digit format? Perhaps two expressions? One with hyphens, and one without? – Ryan B Nov 05 '21 at 14:27
  • Sure. If you want to use a specific number, just replace the `\d` characters with the number you want to match against. `\d` just means to match any digit. So, to match numbers start with `1234`, for example, we would use `1234(-|)\d\d\d\d(-|)\d\d\d\d(-|)\d\d\d\d`, which is to say, `1234`, maybe followed by a hyphen, followed by four more digits, another optional hyphen, another four digits, another optional hyphen, and one last set of four digits. – ian Nov 08 '21 at 21:28
  • And if we didn't want the hyphen pattern? Thanks again! You are helping a ton. – Ryan B Nov 11 '21 at 15:18
  • You can just remove every instance of `(-|)`. That would lead you with a regex matching 16 digits (`\d` 16 times). I don't actually have to deal with Office 365, so it may be that their regex implementation is broader than I was lead to believe. I found this [blog entry](http://blog.chrislehr.com/2014/11/using-regular-expressions-in-exchange.html) from 2014 on a Spiceworks forum (which is another great place to get advice on things like this). It could be a good place for you to start. That and an [online regex playground](https://regex101.com/) will likely get you where you need to be. – ian Nov 11 '21 at 21:31