const regex = /(?<=Set-Cookie: __RequestVerificationToken=).{108}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<=Set-Cookie: __RequestVerificationToken=).{108}', 'gm')
const str = `HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Set-Cookie: __RequestVerificationToken=6JBpdPLoWg2ON0CbCTTCffsZZsCU_rRGlmarVTRfg4Gu1_6FEqpgd_jcLbN_mBWdXJjCeYw6DQ3nxd8hABsNTpRWJALapk9KUZhu6jGkh0I1; path=/; HttpOnly
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
strict-transport-security: max-age=60; includeSubDomains
referrer-policy: strict-origin-when-cross-origin
Set-Cookie: httpOnly
X-Content-Security-Policy: script-src 'self' https://fonts.gstatic.com
Date: Wed, 12 Feb 2020 15:46:34 GMT
Content-Length: 3124`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions