How to mount a regex?

0

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?

    
asked by anonymous 27.11.2017 / 14:27

1 answer

2

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 .

    
28.11.2017 / 10:30