0

It seems like you cant call an argument in your regex expression. Is there such a way? I want it to return true if the key search is in the string.

function sequenceSearch(str, key) {
  console.log(/key/g.test(str));
}
console.log(sequenceSearch('arcata', 'cat')); //true
Ray Jay
  • 11
  • Hi Ray, wellcome to SO. It looks like somebody flagged yout question as a "Duplicate". It means that there is already another anwered question similar to this. I just checked it, and the selected answer would work for you. Don't hesitate to make another question when needed, just remember to check first if there is an anwer for you in SO. – Roimer Mar 17 '21 at 00:28
  • I just looked at the page and I'm still confused as to how to do it – Ray Jay Mar 17 '21 at 00:31
  • `/key/g` is a regular expression. This can also be created using `new RegEx('key', 'g')` where you can replace `'key'` with any string variable you like – evolutionxbox Mar 17 '21 at 00:49

0 Answers0