0

I have the following regex:

var re = /ABCD-\w{3}/

It works as is, but when I use a variable like this:

var myvar = "ABCD" + "-\w\\{3}\\}"
var re = nev RegExp(myvar, "g")

It doesn't work.

bolov
  • 72,283
  • 15
  • 145
  • 224
  • `var re = /ABCD-\w{3}/` = `new RegExp("ABCD-\\w{3}")`. – Wiktor Stribiżew Jul 21 '17 at 14:37
  • Have you tried `var myvar = 'ABCD' + '-\w{3}'` ? When you already have a variable which is used in a regex constructor, it doesn't matter. It only matters about the string parsing rules of the language, has nothing to do with regex at all .. –  Jul 21 '17 at 14:52
  • I tried that: var myvar = 'ABCD' + '-\w{3}' but it didn't either. – Alex Jul 21 '17 at 17:34

0 Answers0