I'm setting up a bot for rocketchat to turn on and off machines in google cloud, I need to mount a regex that covers the words turnon and turnoff. Could someone help me with this?
I'm setting up a bot for rocketchat to turn on and off machines in google cloud, I need to mount a regex that covers the words turnon and turnoff. Could someone help me with this?
As pointed out by @JeffersonQuesado :
/turn(on|off)/g
The first bar indicates the beginning of a regular expression. The parentheses are a capturing group . The pipe acts as a ou
operator . Finally, /g
, which is global search flag .
See running RegExr .
You can then think about adding the case insensitive modifier , /i
, if it's useful to you.
And there in CoffeeScript ...
pattern = /^turn(on|off)/g;
"turndownforwhat".match(pattern);
> null
"turnon".match(pattern);
> [ 'turnon' ]
See working on repl.it .