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 extracting the access code using Regular Expression. The security code email message contains the following message:
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.
With Regular Expression, I was able to isolate the access code, this is what I came up with:
\b[0-9A-Z]{8}\b
I can access the entire message with following:
let msgText = page.FindChild(“idStr”, “msg_panel”, 10).contentText;
How can I isolate the access code using Regular Expression? I really appreciate any help I can get.
Thanks
Dave
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. :)