In Ruby, how can I write a regex to inspect a submission for a single word?
Imagine I have a web form that that accepts text. I know if I want to see if the sentence –only– contains “join” I can use
if the_body == "join"
But that only works if the entire text submission is “join”.
How do I catch a submission like this:
“I want to join your club?” or
“Join me please”
Thanks!
You can do it with
or
A little update regarding the performance comment:
While the speed difference really doesn’t matter here, the regex version was actually faster.