regex help please?

J

Joe Pizzanley

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
 
Q

Quintus

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 09.09.2010 16:43, schrieb Joe Pizzanley:
pens 1234-001
pencils 1234-002
scissors 2345-447

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyI9qUACgkQDYShvwAbcNk5QQCePtFf7AjIyMHgS1x4CGAhQ86b
SV0An1lLEuELca3TVoo8pnAJkNlRGFAw
=GLmf
-----END PGP SIGNATURE-----
 
J

Joe Pizzanley

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top