From: Morton Goldberg Date: 2007-12-08T02:55:53+09:00 Subject: Re: how to use split method in ruby On Dec 7, 2007, at 6:22 AM, dare ruby wrote: > if @news contains 'kick the ball" > i need out put as, like > > kick > the > ball > same if @ news contains 'kick the="size" ball="blue"" > > i need to split and output should be like > > kick > the > ball > Some message : size > blue I'm not sure I understand your question, but here is a guess on how you might get the output you want. str1 = "kick the ball" str2 = 'kick the="size" ball="blue"' def my_split(str, msg) str = str.gsub(/=\"/, ' #').split(/(?:\"\s*)|\s/) words, more = str.partition { |token| token[0] != ?# } unless more.empty? words << msg words << more.map { |token| token.delete("#") } end words end puts my_split(str1, "MESSAGE 1") puts puts my_split(str2, "MESSAGE 2") kick the ball kick the ball MESSAGE 2 size blue It's not very elegant, but maybe it will work for you. Regards, Morton