new RegExp(variable) constructor instead of writing /variable/. After looking through the web I also found a way to add special characters like ^ and $ to specify precisely what I want to match. The syntax for this is:
var myReg = new RegExp('^' + variable + '$');
But I wanted to match the word boundaries, the modifier for this would be ‘\b’ but it didn’t work like that:
var myReg = new RegExp('\b' + variable + '\b');
var myReg = new RegExp('\\b' + variable + '\\b');
I don’t know if anybody is aware of this, I wasn’t and I think it is kind of unexpected since the literal version of this /\\b/ would match a backslash followed by a ‘b’.