0

I have the variable label

const label = 'test'

and the regex

{ name: /test/i }

What I want is know if I can use the variable label inside the regex, something like this

{ name: `/${label}/i` }

Is it possible?

Rodrigo
  • 492
  • 7
  • 27

1 Answers1

1

To use variable in regex, use:

new RegExp(`${label}`, 'i')

Abhishek Pankar
  • 473
  • 4
  • 11