From: "Derrick B." Date: 2012-12-21T13:59:41+09:00 Subject: Re: Perl to Ruby: regex captures to assignment. 7stud -- wrote in post #1089755: > %r{ > ( > [-]? > \d+ > )? > \s* > (\d+) > / > (\d+) > }xms > ) > That works, but it needs another "[-]?" in the second group to handle negative numerators, or whole numbers: %r#(?:([-]?\d+) )??([-]?\d+)/(\d+)#xms ...but I should probably add the "\s*" and not expect a single space. I got the "??" from Perl, but it seems to not be a problem in Ruby. Lastly, my code I posted did not convert terms to improper fractions, correctly. Here is the code that works: Ruby: n = ( w == w.abs ) ? n + w * d : -1 * ( n - w * d ) if d != 0 # to negative improper fraction Perl: $n = ( $w == abs($w) ) ? $n + $w * $d # to positive improper fraction : -1 * ( $n - $w * $d ) if $d; # to negative improper fraction ...which leads me to another question: Why is it that when I try to add a comment after a line continuation backslash, Ruby says: ./ratnum.rb:14: syntax error, unexpected $undefined n = ( w == w.abs ) ? \ # ^ ./ratnum.rb:15: syntax error, unexpected ':', expecting keyword_end Ruby should respect my need for comments! :) -- Posted via http://www.ruby-forum.com/.