Forum Discussion

royd's avatar
royd
Regular Contributor
6 years ago
Solved

Regular Expression to extract a 'word' from string. Need help.

I am trying to extract success code from email message. I was able to do so with “aqString.SubString” method, thanks to Shankar R. I have been practicing Regular Expression and wanted to attempt extr...
  • royd's avatar
    6 years ago

    Okay, I have figured it out! Took a wild guess and it worked. The code below gave me what I was after.

     

     

    let msgBody = "Your AMG - Facility forms access code is 22RP3DPM. You will receive a link to your forms using your primary email address. You will need this access code to use the forms link. Further instructions will be available after using the access code to access the forms.";
    let secCode = msgBody.match(/[0-9A-Z]{8}/); // the '/' before and after [0-9A-Z]{8} specifies it as Regular Expression
    
    Log.Message("Security code is: " + secCode);

     

    Log reads as: "Security code is: 22RP3DPM"

     

    Hope this comes handy for someone else in my situation. :)