From: Suraj Kurapati Date: 2006-12-21T05:07:10+09:00 Subject: Re: Regex question: this should be easy but doesn't work as Sam Kong wrote: > What I want is > > "one two three four five" #=> [["one", "three", "five']] > "one two four five" #=> [["one", nil, "five']] > > In short, in the string, "three" might or might not exist. > What regex can match for both? /one|three|five/ can. Although, its result is not exactly in the form you want: >> "one two three four five".scan /one|three|five/ => ["one", "three", "five"] >> "one two four five".scan /one|three|five/ => ["one", "five"] -- Posted via http://www.ruby-forum.com/.