Hi,

"Tom Sawyer" <transami / transami.net> wrote in message
news:1025760825.2466.193.camel / silver...
> per your code:
>
....
>
> it still has one problem though. it falls into an infinite loop
> if the last part of the string isn't contained by any tokens.
> for example if an l is added:
> str = 'a<b>[c]{d}"e"f {{g}} [[h]]*i**j*"k"l'
> i'm sure this could be easily fixed.
>

Here is my second version:

-------------------------------------------------------------------
str = 'ad3<b>[c]{d}"e"f {{g}} [[h]]*i**j*"k"ll"sdfsd"z'

s = ['<','[','{','"','*']
e = ['>',']','}','"','*']
arr = []

i = 0
while i< str.length

  if not s.include?(str[i,1])
     j = i+1
     j += 1 while j<str.length && !s.include?(str[j,1])
     arr << str[i..j-1].strip
     i = j
  end

  for j in 0 ... s.length
    if str[i,1] == s[j]
      if s[j]=='"' || s[j]=='*'
        k = str.index(e[j],i+1)
      else
        k = i
        k += 1 while str[k,1]==s[j]
        k = str.index(e[j],k)
        k += 1 while k+1<str.length && str[k+1,1]==e[j]
      end
      arr << str[i..k]
      i = k+1
      break
    end
  end
end

p arr
------------------------------------------------------------

> did you take a look at sean's version, by the way?
> a tad more elegent although he does use regexps.
>
Sean's version fails at
str = 'a<b>[c]{d}"e"f {{g}} [[h]]*i**j*"k"l'

> ~transami
>

Park Heesob.