using (word|other) in str.include?

J

James Dinkel

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?
 
S

Sebastian Hungerecker

James said:
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
 
J

James Dinkel

Sebastian said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,661
Latest member
sxarexu

Latest Threads

Top