From: David Wright Date: 2008-12-04T02:28:14+09:00 Subject: Re: string with \ Vrone Ve wrote: > Vrone Ve wrote: >> Rob Biedenharn wrote: >>> On Dec 3, 2008, at 10:12 AM, Vrone Ve wrote: >>> >>>> cheers >>> irb> string = "abc/ def/ ghi/" >>> => "abc/ def/ ghi/" >>> irb> string.split(%r{/\s*}) >>> => ["abc", "def", "ghi"] >>> >>> You could use parallel assignment, but I'd question whether you really >>> wanted three variables rather than a three-element array. >>> >>> a, d, g = string.split(%r{/\s*}) >>> >>> >>> -Rob >>> >>> Rob Biedenharn http://agileconsultingllc.com >>> Rob@AgileConsultingLLC.com > > thanks Rob, and all for your response > > My detailed question is regarding a string something like > String "ABC\Name X\Gender " > and I want to scan the string for each of the element(i.e. Name, Gender) > and whereever Name is written in the string, I want to grab the value > placed before the back slash and store it in a variable. same is the > case with gender and/or with any other attribute i want to be in this > string. > > Your help required. > cheers rather then split, I believe you want scan. irb(main):032:0> str = 'ABC\Name X\Gender Z\Person ' => "ABC\\Name X\\Gender Z\\Person " irb(main):033:0> str.scan(/(.*?)\\\w+\s?/) => [["ABC"], ["X"], ["Z"]] irb(main):034:0> t = str.scan(/(.*?)\\\w+\s?/) => [["ABC"], ["X"], ["Z"]] irb(main):035:0> t => [["ABC"], ["X"], ["Z"]] -- Posted via http://www.ruby-forum.com/.