Parse Function - substringBetween


#1

HI,

I am trying to use the string parsing method on the message body of an incoming HTML email. I can get this to partially match, but the output contains some new lines/carriage returns. My goal is to try and match on the new line in the message.substringBetween parse, so that I only output a single concise line of text.

Input I am trying to parse:

Message-ID
(New Line)
<a8d3f544e2fb41b05062daa9b172f7d8@fedex.com<mailto:a8d3f544e2fb41b05062daa9b172f7d8@fedex.com>>

Parse I am using:

{{message.substringBetween(“Message-ID”,"<mailto:")}}

Output:

(newline)
<a8d3f544e2fb41b05062daa9b172f7d8@fedex.com

Non-working desired command

{{message.substringBetween(“Message-ID\n<”,"<mailto:")}}

Desired output:

a8d3f544e2fb41b05062daa9b172f7d8@fedex.com

P.S. I have also tried RegEx extract and that is a nightmare. I can partially get matches. Things that work in regex testers perfectly won’t translate over to opsgenie unfortunately.

If regex is the way to go. My problem there is for some reason it wont match on a space. I have tried to escape the space as a test, i.e. “Message-ID\ \n”


#2

Hi Matt!

I think you were working on this with us in our chat support last week when you got up to this point. Would it be possible to head back to our chat and send over a “raw” copy of the email (save a copy and attach the file)? I’d expect something like what you have, {{message.substringBetween(“Message-ID\n<”,"<mailto:")}}, to work but obviously something else is preventing a match.

Checking the HTML version that’s attached to the alert shows something different from what we appear to be processing:

Chaining two substringBetween functions (with the first one you listed then a second to remove the “\n<”) might also help in this case.


#3

@Robert, thank you for the help on this! OpsGenie support is great! We were able to work on this together and quickly came to a solution.

For those interested we were able to get a match using, {{message.substringBetween(“Message-ID\r\n\r\n<”,"<")}}

The parse is able to interpret Newline \n and Carriage return \r.