From: "Hal E. Fulton" Date: 2002-08-01T01:06:57+09:00 Subject: Re: Individual elements of regular expressions ----- Original Message ----- From: "Maur�cio" Newsgroups: gmane.comp.lang.ruby.general To: "ruby-talk ML" Sent: Wednesday, July 31, 2002 9:10 AM Subject: Individual elements of regular expressions > How do I say: in a set of (number G number number1 number number > end-of-line --CONT- number number2 number number end-of-line), I want to > know number1 and number2? I think David perhaps answered half your question... I'll address the other half. I think you want backreferences. If you parenthesize part of a regex, then you can retrieve it afterward as a separate entity. You can use the Perlish shorthand \1, \2, etc. in some cases or you can use the array-like MatchData object. Look it up in the Pickaxe Book or in _The Ruby Way_. A MatchData example (doing this from memory, so it may be wrong): reg = /(.)2(.)2/ str = "R2D2" md = reg.match(str) puts md[0] # "R2D2" (the entire match) puts md[1] # "R" puts md[2] # "D" Hope this helps. Hal