[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

using (word|other) in str.include?

James Dinkel

7/23/2008 8:53:00 PM

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?
--
Posted via http://www.ruby-....

2 Answers

Sebastian Hungerecker

7/23/2008 8:59:00 PM

0

James Dinkel 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
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

James Dinkel

7/24/2008 9:40:00 PM

0

Sebastian Hungerecker wrote:
> James Dinkel 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!
--
Posted via http://www.ruby-....