str = "class#1 hello world class#2 goodbye class#3 hi"

arr = str.split(/ (class\#\d) /xms)
p arr

arr.shift

while arr.length > 0
  puts arr.slice!(0,2).join
end

--output:--
["", "class#1", " hello world ", "class#2", " goodbye ", "class#3", " 
hi"]
class#1 hello world
class#2 goodbye
class#3 hi

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