cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with Regex

Rajorigin
Specialist

Hi team,

I want to include a set of users to an existing segment. This segment will be used for exclusions in all promotional campaigns. Let's call that segment as Level 3. The set of users are subscribers for a specific product. I know that I can't create a segment only for these set of users and include that segment in Level 3 as Level 3 is used in all marketing campaigns and Braze doesn't alllow me to do that. Therefore, one way to bell this cat is to use a "match regex" filter condition in Level 3 to identify that cohort that I want to exclude. The regex can target a custom attribute called "Active_Accounts". The "Active_Accounts" is a string and lists all the active account numbers for the user. The account numbers are comma separated and the product that I am targeting ( for the set of users) appears as the first value in "Active_Accounts". The account number for the set of users will follow this pattern : oabc-32HABHCPUV {10} or odefg-12AAAAAB {8} etc. But the account number always starts with a 'o' (lower caps). Need help to create a regex that I can match from the "Active_Accounts" so I can include this set of users in Level 3 using the match regex filter

 

9 REPLIES 9

DavidO
Strategist

Hey @Rajorigin 

I think I understand your need and my regex is not amazing but this might help get the conversation started.

o[a-z]{3,4}-\d{1,2}

Where 'o' is the lower case 'o', '[a-z]{3,4}' is looking for any sequence of 3 to 4 lowercase letters after the 'o' as it appears some users may have 3 and some may have 4. The '-' is just that, and the '\d{1, 2}' is looking for any one or two digit numbers on the end, as it looks like they could have 8, or 10 or probably other numbers.

So, you know, I built this by putting your question into CoPilot, which got me 95% there and then used Regex101  to test and debug what CoPilot gave me with your strings. 

😊

Hello David, 

Thanks for the revert much appreciated. I tried similar regex before, and it worked. But in my specific used case I need only that user that has got only one account starting with "o" and they should not have any other account numbers. For example, the custom attribute will have values like A-123456, oxxx-AB12345689. I do not want this customer because they have another account starting with A. If there is a filter condition "does not matchregex" that would have been easier, but I can't see that.

Cheers/ Raj

Hmm, yeah that's a trickier one for sure. I know you can use regex to reject or match certain values, positive and negative lookahead, but my knowledge of it would be limited at best. It might be worth investigating.

bob
Specialist

If there can only be a single instance of the account number, then you could keep it simple using
starts with 'o' and does not contain a comma.

If you need to more robustly match your account numbers, then you'd need to be more specific with the rules, but given what you've said already, something like this should work.

^o[a-z]{3}-[0-9A-Z]{8,10}$

Using the start and end of string characters (^ and $) to make sure there was only one instance.

If you had a list of things that should match and things that should not, I can probably better refine what you're looking for.

(and as David said, it's a starting point for a conversation.)