0

In javascript regex, I have the following capture pattern, see regexCapture:

rsqlFilter = "(testId==\"*abcd*\",tenantName==\"*abcd*\",applicationName==\"*abcd*\",projectName==\"*abcd*\")";
let regexCapture = /testId=="\*(.+?)\*"/;
let matchx = rsqlFilter.match(regexCapture);
console.log(matchx[1]);  // it's the string abcd

Now, I want that columnName testId to be dynamic, a variable, instead of hard coded text. How do I do that as the following code below will fail to capture?

rsqlFilter = "(testId==\"*abcd*\",tenantName==\"*abcd*\",applicationName==\"*abcd*\",projectName==\"*abcd*\")";
let columnName = 'testId';
let regexCapture = `/${columnName}=="\*(.+?)\*"/`;
let matchx = rsqlFilter.match(regexCapture);
console.log(matchx[1]);  // -----------> WILL FAIL!
RonPringadi
  • 1,064
  • 1
  • 12
  • 34

0 Answers0