# Using (word|other) in str.include?

**URL:** <https://www.ruby-forum.com/t/using-word-other-in-str-include/143928>\
**Category:** Ruby\
**Created:** [July 23, 2008, 10:58pm UTC](https://www.ruby-forum.com/t/using-word-other-in-str-include/143928 "2008-07-23T22:58:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [July 23, 2008, 10:58pm UTC](https://www.ruby-forum.com/t/using-word-other-in-str-include/143928/1 "2008-07-23T22:58:55Z")

</div>

Using ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

I’m going over an old script I wrote and I have an if statement that  
basically goes like this:

do something if mystring.include?(“something (word1|word2): something”)

This script worked fine with this for months, but now I’m updating it  
and re-“compiling” it with rubyscript2exe. I think I previously  
“compiled” it with a prior version of ruby, so that could be the cause  
of my current woes. Anyway, the (…|…) part is not working now.

I’m playing around with it in irb and it will only match mystring if I  
place word1 or word2 directly into the compare string rather than using  
(word1|word2). Does this ability not work anymore? Is there something  
equally succint I can do rather than writing out two if statements?

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [July 23, 2008, 11:04pm UTC](https://www.ruby-forum.com/t/using-word-other-in-str-include/143928/2 "2008-07-23T23:04:54Z")

</div>

James D. wrote:

> do something if mystring.include?(“something (word1|word2): something”)

It surprises me quite a bit that that ever worked. Here’s what should  
work:  
do something if mystring =~ /something (word1|word2): something/

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![jimdeuc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@jimdeuc](https://www.ruby-forum.com/u/jimdeuc)\
**Post date:** [July 24, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/using-word-other-in-str-include/143928/3 "2008-07-24T23:46:11Z")

</div>

Sebastian H. wrote:

> James D. wrote:
> 
> > do something if mystring.include?(“something (word1|word2): something”)
> 
> It surprises me quite a bit that that ever worked. Here’s what should  
> work:  
> do something if mystring =~ /something (word1|word2): something/
> 
> HTH,  
> Sebastian

yep, that works. Thanks!
