From: Joel VanderWerf Date: 2004-04-14T07:35:00+09:00 Subject: Re: New Ruby questions... Jeff Massung wrote: > 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? I get the same problem with opcode mnemonics (like B > instead of BX or BL). Is this what you want to do? irb(main):001:0> registers = '(r0|r1|r2|r3...|r10|r11|r12...)' => "(r0|r1|r2|r3...|r10|r11|r12...)" irb(main):002:0> irb(main):003:0* registers.scan(/r\d+/) => ["r0", "r1", "r2", "r3", "r10", "r11", "r12"]