Event Rule Regex Parsing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 08:37 AM
I am trying to parse an email with regex in an event rule and keep running into issues. Have tested over a dozen different ways to parse but everything keeps returning extra content or returns <<unknown>>.
Current regex is just trying to get Service but I ultimately need a few different things.
.*Service:\s(.*).*
What I am trying to parse looks like this -
-----------------------------------------------
email body text that changes and is useless. Contains some times 10:00 pm etc. and other info that is unimportant.
Service: important company info
Data Center: US East
Identity Domain: important423525
Then there is a whole bunch of unimportant stuff down here that we don't need.
--------------------------------------------
What I am trying to get is an expression that has the data after Service, Data Center and Identity Domain. Any suggestions would be greatly appreciated.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 09:09 AM
Hi,
How about parsing the data line by line, and when handling each line, look for the specific texts, and store the needed information in a variable to use after all the processing (all text is read) is done.
Otherwise you will need to create 3 separate regular expressions, or a very complicated one, to match these texts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 09:49 AM
The plan is to create 3 separate expressions. I have been trying to just get the first thing to work here first. Have not had luck without specifying exactly what we are expecting to see in the match string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 09:18 AM
Hi,
May be you can use split('\n') to break each line into an array element and go through each line and get required data.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 10:21 AM
Hi Jordan,
I have created the following background script to demonstrate regex usage as per your requirement. Although, it might need some fine tunings.
var str = "-----------------------------------------------'\n'\nemail body text that changes and is useless. Contains some times 10:00 pm etc. and other info that is unimportant.'\n'\nService: important company info'\n'\nData Center: US East'\n'\nIdentity Domain: important423525'\n'\nThen there is a whole bunch of unimportant stuff down here that we don't need.'\n'\n'\n'\n --------------------------------------------"
gs.print(str.match(/Service: [a-z\s]*/ig));
gs.print(str.match(/Data Center: [a-z\s]*/ig));
gs.print(str.match(/Identity Domain: [a-z0-9\s]*/ig));
Output
Hopefully, this will help you fine tune your regex.
