I have a channel in slack where automated message is posted. The message looks like this:
A ticket is submitted by: @abc
Request Title test
Requested For @xyz
Requested system? MMM
See here for the ticket.
What i need to do is to fetch the system name ‘MMM’ or there can be multiple system name separated by comma.
I am trying the following appscript code but this is not fetching anything:
function extractData(message) {
const regexRequestedSystem = /Requested system?n(.*?)$/s;
const requestedSystemMatch = regexRequestedSystem.exec(message);
return {
requestedSystem: requestedSystemMatch ? requestedSystemMatch[1].trim() : null,
messageLink: `https://slack.com/app_redirect?channel=${channelId}&message_ts=${message.ts}`,
};
}
Could you please help me with the regex syntax?
Thank you!!
I tried this syntax:
const regexRequestedSystem = /Requested system?n(.*?)$/s;
but this is not fetching anything. I need to fetch the ‘MMM’ only like I said before.
2
Answers
Here you can get Requested system Names in an array
Try this approach
I used Google Docs to give as a sample for your question and here’s some modification on your code.
Regex
const regex = /Requested system?s*(.+)/;
This part is a capturing group
()
that matches one or more characters(.+)
after the spaces.This will capture everything that follows
"Requested system?"
in the document, which could be the list of systems or any other content.Modified Script
Sample Validation
Reference