Regex help please?

I've looked at regular expression documentation for hours, but I'm
wondering if someone would have pity on me and just slip me the answer.
What I want to do is get each of the item numbers on a list:

onscreen:
         pens 1234-001
         pencils 1234-002
         scissors 2345-447

I'm thinking the numbers would go into an array... I'd be happy with any
ideas.

much thanks!!
Joe

···

--
Posted via http://www.ruby-forum.com/.

You mean, like this?

irb(main):001:0> str =<<STR
irb(main):002:0" pens 1234-001
irb(main):003:0" pencils 1234-002
irb(main):004:0" scissors 2345-447
irb(main):005:0" STR
=> " pens 1234-001\n pencils 1234-002\n
   scissors 2345-447\n"
irb(main):006:0> str.scan(/(?:\d|\-)+/)
=> ["1234-001", "1234-002", "2345-447"]
irb(main):007:0>

Vale,
Marvin

···

Am 09.09.2010 16:43, schrieb Joe Pizzanley:

         pens 1234-001
         pencils 1234-002
         scissors 2345-447

Marvin Gülker wrote:

irb(main):006:0> str.scan(/(?:\d|\-)+/)

works for me. many thanks!

···

--
Posted via http://www.ruby-forum.com/\.

sometimes I end up with 2 of the same thing, how would I remove the
duplicate?

···

=> " pens 1234-001\n pencils 1234-002\n
   scissors 2345-447\n pencils 1234-002\n"

--
Posted via http://www.ruby-forum.com/\.

=> ["a", "b", "c", "d"]

-Rob

Rob Biedenharn
Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
rab@GaslightSoftware.com http://GaslightSoftware.com/

···

On Sep 9, 2010, at 4:55 PM, Joe Pizzanley wrote:

sometimes I end up with 2 of the same thing, how would I remove the
duplicate?

=> " pens 1234-001\n pencils 1234-002\n
  scissors 2345-447\n pencils 1234-002\n"

--
Posted via http://www.ruby-forum.com/\.

["a", "b", "c", "a", "d", "c"].uniq

> ["a", "b", "c", "a", "d", "c"].uniq

Thanks Rob! Works like a charm.

Joe

···

--
Posted via http://www.ruby-forum.com/\.