I have a character class that I want to use multiple times without copy-pasting it. So, turning something like:
let s = 'Hello, James_1234'
let re = /Hello, [wd-_]+/
console.log(re.test(s)) // => true
Into something more like:
let s = 'Hello, James_1234'
let legalNameChars = /[wd-_]/
let re = /Hello, @{legalNameChars}+/
console.log(re.test(s))
Obviously the above code does not work, because that’s string interpolation syntax and is not applicable here. I am also aware that I could convert everything to strings and back—I would like to interpolate them directly in regex literals if possible.