joep
September 9, 2010, 4:43pm
1
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
joep
September 9, 2010, 5:01pm
2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am 09.09.2010 16:43, schrieb Joe P.:
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-----
joep
September 9, 2010, 8:23pm
3
Marvin Gülker wrote:
irb(main):006:0> str.scan(/(?:\d|-)+/)
works for me. many thanks!
joep
September 10, 2010, 1:45am
4
On Sep 9, 2010, at 4:55 PM, Joe P. 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/ .
irb> [“a”, “b”, “c”, “a”, “d”, “c”].uniq
=> [“a”, “b”, “c”, “d”]
-Rob
Rob B.
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/
joep
September 10, 2010, 4:43pm
5
irb> [“a”, “b”, “c”, “a”, “d”, “c”].uniq
Thanks Rob! Works like a charm.
Joe
joep
September 9, 2010, 10:52pm
6
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"