Hi, Below are two tests of using MatchData. The first is essentially Hal Futon''s taken from The Ruby Way, 2nd. ed. [Thanks, Hal]. In particular, m[0] returns the string being searched. The 2nd is my humble use. For mine, m[0] returns the search pattern, it seems, I can''t anything in the code to account for this difference. I''m expecting the first kind of response in a Rails app I''m working on, but I''m getting the second kind of response. Any ideas? Thanks in Advance, Richard BTW, I running Ruby 1.8.6 over WindowsXP-Pro.SP3 ========= Test ========puts "\n1." pat = /(.+[aiu])(.+[aiu])(.+[aiu])(.+[aiu])/i str = "Fujiyama" m = pat.match(str) (0..5).to_a.each { |i| puts "m[%d]: %s" % [i, m[i].to_s] } puts "\n2." pat = /noun/i str = "The ''noun'' word is here" m = pat.match(str) (0..5).to_a.each { |i| puts "m[%d] %s" % [i, m[i].to_s] } -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Feb 28, 2010 at 12:16 PM, RichardOnRails <RichardDummyMailbox58407-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote:> Hi, > > Below are two tests of using MatchData. The first is essentially Hal > Futon''s taken from The Ruby Way, 2nd. ed. [Thanks, Hal]. In > particular, m[0] returns the string being searched. > > The 2nd is my humble use. For mine, m[0] returns the search pattern, > it seems, > > I can''t anything in the code to account for this difference. I''m > expecting the first kind of response in a Rails app I''m working on, > but I''m getting the second kind of response. > > Any ideas?m[0] doesn''t return the string being searched, it returns everything which the entire pattern matched. In the first case /(.+[aiu])(.+[aiu])(.+[aiu])(.+[aiu])/i entirely matches "Fujiyama" in the second case /noun/i only matches a portion of the string, so that''s what is the value of m[0] -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Rick,> m[0] doesn''t return the string being searched, it returns everything > which the entire pattern matched.I got it! In Hal''s example, the matched string just happened to be the entire string. I didn''t realize that distinction, but I''m on board now. Thanks again for upteenth time for pulling my fat out of the fire. Best wishes, Richard On Feb 28, 12:32 pm, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Feb 28, 2010 at 12:16 PM, RichardOnRails > > <RichardDummyMailbox58...-gP6xRNRnnqSxhq/XJNNIW0EOCMrvLtNR@public.gmane.org> wrote: > > Hi, > > > Below are two tests of using MatchData. The first is essentially Hal > > Futon''s taken from The Ruby Way, 2nd. ed. [Thanks, Hal]. In > > particular, m[0] returns the string being searched. > > > The 2nd is my humble use. For mine, m[0] returns the search pattern, > > it seems, > > > I can''t anything in the code to account for this difference. I''m > > expecting the first kind of response in a Rails app I''m working on, > > but I''m getting the second kind of response. > > > Any ideas? > > m[0] doesn''t return the string being searched, it returns everything > which the entire pattern matched. > > In the first case /(.+[aiu])(.+[aiu])(.+[aiu])(.+[aiu])/i entirely > matches "Fujiyama" > > in the second case /noun/i only matches a portion of the string, so > that''s what is the value of m[0] > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Twitter:http://twitter.com/RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.