0
I’m assembling a bot for rocketchat to turn machines on and off in google cloud, I need to assemble a regex that covers the words Turnon and turnoff. Someone could help me with this?
0
I’m assembling a bot for rocketchat to turn machines on and off in google cloud, I need to assemble a regex that covers the words Turnon and turnoff. Someone could help me with this?
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 operator ou
. Finally, the /g
, which is the global search flag.
Behold running on the Regexr.
You can then think about adding the case modifier insensitive, /i
, if it helps you.
And there in Coffeescript...
pattern = /^turn(on|off)/g;
"turndownforwhat".match(pattern);
> null
"turnon".match(pattern);
> [ 'turnon' ]
Behold running on repl.it.
Browser other questions tagged regex coffeescript
You are not signed in. Login or sign up in order to post.
/turnon|turnoff/g
?– vinibrsl
@vnbrs
/turn(on|off)/g
?– Jefferson Quesado
@Jeffersonquesado
/turno(n|ff)/g
?– vinibrsl
@vnbrs thought about it too, but then lost semantics by a questionable gain of structure
– Jefferson Quesado
@Jeffersonquesado is when avoid redundancy tends to exaggerate
– vinibrsl