samedi 7 mars 2015

nodejs variable in regex match() [duplicate]


This question already has an answer here:




how can I use a variable in match() if I want to use regex? This works fine for me:



if (message.match('!' + cmd)) {
this.client.say(to, myJson[cmd]);
}


but if I try something like this it will not check the variable.



if (message.match(/!cmd/i)) {
this.client.say(to, myJson[cmd]);
}


I already searched for a solution but could only find something for replace.


Aucun commentaire:

Enregistrer un commentaire