How to extract URL from email body using JavaScript and Regex?

King Java 500 Reputation points
2024-10-17T01:38:43.31+00:00

I am posting this for the third time because for the last two times, I had an issue with getting the right Regex (ECMAScript) for the URL that I was trying to convert (from email body), but it appears that this Regex should be good one as I verified with Regex101.

User's image

I have Logic App that looks like bottom:

User's image

I am trying to get part of email text like below:

originalsrc="https://portal.carefeed.com/xxxxx/reports/report/emailReport?details=60a286e8-d616-452c-87a5-65ccff6f01cb"

Why do I get "InvalidCodeScriptRunTimeFailure"?

Bottom is JavaScript that I was using on the third process (Execute JavaScript Code).

const jsonString  = workflowContext.trigger.outputs.body.bodyPreview;
const jsonObject = JSON.parse(JSON.stringify(jsonString))
const regex = /originalsrc=\\"https:\/\/(www\.)?\w+(\.\w+).*$"/;
   
const match = jsonObject.match(regex);
   
   if (match) {
       return "Matched"
   } else {
       return "No Match"
   }

Bottom are two posts that I asked:

https://learn.microsoft.com/en-us/answers/questions/1696123/how-to-extract-url-link-from-email-body-using-azur

https://learn.microsoft.com/en-us/answers/questions/1684590/extract-url-link-behind-email-body-using-azure-log

And this is article that I got some clue to start with:

https://learn.microsoft.com/en-us/answers/questions/1350491/extract-url-link-behind-email-body-using-logicapps

Thank you.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,162 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.