I found a bug... It didn't like strings that *started* with a
delimiter.  Anyways, here's a quick fix, just putting it out in
the off chance anyone would be using this stuff. It got quite a bit
uglier. I bet any of the Dave's out there could cut the code size by a
significant amount and perhaps trim the run time. Run time is
important to me because this routine will be called a lot in an
interactive setting.

Hopefully there are no more bugz, but if I do find another, I'm not going
to post here again (too much noise), just ask me and I'll send you the
latest.

def asplit_text(pre_str, post_str, string)

  results = [];  s = []; e = []; ranges = []
  slen = pre_str.length; elen = post_str.length
  pos = 0
  while pos = string.index(pre_str,pos)
    s <<  pos
    pos += slen
  end
  pos = 0
  e << pos while pos = string.index(post_str,pos+elen)

  # get the ranges of the parts with delimiters
  start = s[0]; len = s.length-1
  1.upto(len) do |x|
    if s[x] > e[x-1]
      ranges << [start,e[x-1]]
      start = s[x]
    end
  end
  ranges << [start,e[-1]] # catch the last one...

  # merge it with the parts outside the delimiters

  # if the *first* element is surrounded by delimiters:
  if(s[0] == 0)
    last = ranges[0][1]
    results << string[0..last+elen-1]
    ranges.shift
  else
    last = -elen
  end

  # all the rest
  ranges.each do |range|
    if range[0] > last
      results << string[last+elen..range[0]-1]
      last = range[1]
      results << string[range[0]..last+elen-1]
    end
  end

  # catch the trailing string if needed
  if ranges[-1][1]+elen-1 < string.length-1
    results << string[ranges[-1][1]+elen..string.length]
  end

  print "original string: "; p string
  print "ranges: ";   p ranges
  print "resulting array: ";   p results
end

asplit_text("{{", "}}", "{{start}} {{blah\n\n {{ {{  }} }} }} {{ asdf }} out {{ {{ }} }} bye")
puts "--------------------"
asplit_text("(", ")", "()Hello ( ( World ) ) () (  ) ((())) Goodbye ()" )
puts "--------------------"
asplit_text("{{", "}}", "  {{start}} {{blah\n\n {{ {{  }} }} }} {{ asdf }} out {{ {{ }} }} bye")
exit

-joe