I have code:

<% @terms.each do |term| %>>

  <%regex = Regexp.new(/#{term}/)%>
  <%matchdata = regex.match(@def_str)%>
  <%if matchdata%>

    <%  @def = @def.split(/#{term}/) %>
    <%  @def.shift %>

  <%end%>
<%end%>

I want to be able to take a list of terms and a string of text (a
definition) and find the terms in the text.  If a term is found in the
definition, the program is supposed to split the definition on that term
and then discard everything in the definition before the term was found.

So if I have terms: cuddly, soft and cute

and the def = "teddy bears are cuddly stuffed animals which are
generally soft and given to cute children"

my program should change def so that after checking for cuddly, def
looks like:

"stuffed animals which are generally soft and given to cute children"

and after it checks for soft, def should become "and given to cute
children"

and so on.

The splitting and shifting works for the first term on @terms(which is
an array)
but if a second term is found which matches a word in the definition,
def is not split on that word and the whole definition string is
shifted.

Can anyone tell me why split is not working the second time a matching
term is found?

thanks
-- 
Posted via http://www.ruby-forum.com/.