Email Integration Regex Filter based on Subject
Asked by Scott Wright:

I've created an email integration where an alert will be created and prioritized based on the subject.

Here is the Subject from the Debug Logs: **"Incident Assigned: ID: \[IR244691\] Priority: 3"**

The email regex filter: **/Priority:\\s\[3-4\]/g**

I've used regex testers and it correctly matches the subject ( I want to match Subjects with Priority: 3 and Priority: 4 ).

The Logs indicate that the email is received, but no matches were made. Is there a trick to using regex in Opsgenie? Can someone tell me the correct regex to use for this?


Answers:
author: robert
body: Hi [@Scott Wright](/t5/user/viewprofilepage/user-id/3747829)!

I think I helped you resolve this in a support ticket yesterday but also wanted to include the answer here in case someone else runs into a similar problem:

> I think the "trick" we are looking for is that we are *technically* trying to match regex across the entire field you are parsing. So instead of Priority:\\s\[3-4\], something like .\*(Priority:\\s\[34\]).\* would do the trick.
>
> When checking it in a regex tester, we want the entire field to be colored: <https://regex101.com/r/OMaPwT/1>
>
> Another note is that the start/end slashes and global flags for regex aren't needed here. This page has some more information on setting up these filters and how to format the regex: <https://docs.opsgenie.com/docs/regular-expressions>

comments: author: Scott Wright
body: Yes, your solution worked for me. Thanks!


author: Mikel Stous
body: I'm trying to pull out the node, location, and issue from a long email and this isn't working for me. I tried it off your regex101.com link and it worked there.

**Integration Extra Properties:**

Node: {{ message.extract( /.\*Node:\\s(.\*).\*/ ) }}

Location: {{ message.extract( /.\*Location:\\s(.\*\\n).\*/ ) }}

Issue: {{ message.extract( /.\*Issue:\\s(.\*\\n).\*/ ) }}

**Example email body:**

Service: DNS

Node: NYCSERVER1

Location: NYC New York

Issue: Server not Responding

Room: 443

Rack: 12B

**Expecting**

Node = 'NYCSERVER1'

Location = 'NYC New York'

Issue = 'Server not Responding'


author: Mikel Stous
body: Follow up. This is working for me.

*Name Value*

Node {{ message.extract( /.\*Node:\\s(.\*).\*/ ) }}

Location {{ message.extract( /.\*Location:\\s(.\*\\n).\*/ ) }}

Issue {{ message.extract( /.\*Issue:\\s(.\*\\n).\*/ ) }}


author: Samir
body: Hi [@Scott Wright](/t5/user/viewprofilepage/user-id/3747829) - could you provide a screenshot of the email integration filter you have created? It sounds like you're trying to set a filter on an email integration to only create alerts if the subject contains "Priority: 3" or "Priority: 4", right?

If so, the following examples should work...

1. Just add a filter set to "match one or more conditions" that will create an alert if the subject contains either "Priority: 3" *or* "Priority: 4"

![Image 2020-05-07 at 11.31.44 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/93888i6D4506C89B2B534E/image-size/large?v=v2&px=999 "Image 2020-05-07 at 11.31.44 AM.png")

2. Setup the regex filter like this...

![Image 2020-05-07 at 11.33.28 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/93889i566F7743D8E53AAB/image-size/large?v=v2&px=999 "Image 2020-05-07 at 11.33.28 AM.png")

Either of those options should work if you're trying to have the integration create alerts *only* when it receives an email with "Priority: 3" or "Priority: 4" in the subject of the email.

Hope that helps!

Thanks,

Samir


author: Afonso Henrique Rodrigues Alves
body: Thanks for this question.


Tags: regex