0

Im trying to add a variable into a reg expression. I believe its called backreference but cannot seem to figure out how to create a string+variable to search for that cookie. I tried making it a template literal and adding a string within.

I've been referencing this similar question and have attempted many solutions but am struggling to get this to work properly. I've tried replacing it with replaceAll("searchCookie", 'searchCookie${this.type}')

Backstory: I have a function that will create the base searchCookie + this.type inside my checkCookie function I run this command to get the cookie if it exists or not. Let me know if any details are missed and i appreciate the advice/help

cookie.match(/^(.*;)?\s*searchCookie+Variable\s*=\s*[^;]+(.*)?$/)

Pwntastic
  • 433
  • 1
  • 8
  • 20

1 Answers1

0

try this

var x="abcd"
cookie.match('/^(.*;)?\s*'+ x +'\s*=\s*[^;]+(.*)?$/')
Ayoub Benayache
  • 1,046
  • 12
  • 28
  • While your code may answer the PO's question, you should add a brief explanation of what you have done and how that solves the problem. – giuseppedeponte Nov 16 '19 at 13:34