I’m trying to extract the link inside href and store it in a variable. Please see my code snippet below. Note that the token id is expected to be different with every single run. Thank you for your help.
JavaScript
x
8
1
const body = <html><head></head><body><p>This is SignUp Email with confirmation link</p><p><a href = "http://www.company.com/ls/click?upn=tokenid-11111-22222-333333-444444-555555-xxxxxx"></a></p></body></html>
2
const activation_link = ???
3
console.log(activation_link)
4
/*
5
The expected result to be printed on Console:
6
"http://www.company.com/ls/click?upn=tokenid-11111-22222-333333-444444-555555-xxxxxx"
7
*/
8
Advertisement
Answer
JavaScript
1
3
1
const body = `<html><head></head><body><p>This is SignUp Email with confirmation link</p><p><a href = "http://www.company.com/ls/click?upn=tokenid-11111-22222-333333-444444-555555-xxxxxx"></a></p></body></html>`
2
const matched_links = body.match(/(?<=")http.+(?=")/);
3
console.log(matched_links);