On Fri, Mar 11, 2011 at 9:12 PM, 7stud -- <bbxx789_05ss / yahoo.com> wrote:

> 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/.
>
>
It still needs to be better defined, his/her example delimiter is "class#{i}
 here will be any text    ", so it isn't correct to assume the delimiter
ends after the first digit. We really need more data, to understand what
he/she actually wants to have happen, if you throw a splat in there, it will
eat up the rest of the string.

Another issue that could arise is if input is a large file, it could be too
big to fit into memory, in this case, you might be able to use strscan from
the standard library, or maybe have to find a gem to handle it, not sure, OP
needs to give more information.