From: Robert Klemme Date: 2004-04-14T17:04:13+09:00 Subject: Re: New Ruby questions... "Armin Roehrl" schrieb im Newsbeitrag news:407C6D08.2080509@xss.de... > > > > >1. How can a regexp get the longer of two possibilities that are > >ambiguous? For example, I need to be able to strip out register names: > > > >registers = '(r0|r1|r2|r3...|r10|r11|r12...)' > > > >In the regular expression, how can I get it to find r10 or r11 instead of > >stopping at r1? > > > register =~ /(r\d{2,})/ I guess he rather wants {1,2} some_string.scan(/r\d{1,2}/) do |reg| puts "Found register: #{reg}" end You can even convert that to a number easily: some_string.scan(/r(\d{1,2})/) do |match| no = match[0].to_i puts "Found register: #{no}" end Regards robert > p $1 #-> r10 > > \d is for a digit character > {m,n} at least m and at most n repetitions of the preceding > > more info: > http://dev.faeriemud.org/ruby-uguide/uguide05.html > http://www.rubycentral.com/ref/ref_c_regexp.html > >