From: Tom Rauchenwald Date: 2006-05-25T14:56:18+09:00 Subject: Re: Regexp to esclude substrings vincent writes: > I'm trying to resolve a very simple problem, but I'm encountering some > issues. > > Input: "this is a string where you can find some words" > Output: [this, string, where, can, find, some, words] > > So I'm trying to eliminate ' is ', ' a ' and ' you ' from the string > (note the spaces, 'this' shouldn't be eliminated just because it > includes 'is'). > > I tried the following (and many others), but it doens't work: > my_string = input_string.gsub!(/\s+(is|a|you)\s+/i,' ').split > > Any hints? Well, since you want an array of the words back, why don't you do something like my_string.split.reject { |word| word =~/^(is|a|you)$/ } or my_string.split.reject { |word| %w(is a you).include? word } Seems simpler to me than to replace the words in the string and then split it into an array. Tom > -- > Posted via http://www.ruby-forum.com/.