# Regex help please?

**URL:** <https://www.ruby-forum.com/t/regex-help-please/194726>\
**Category:** Ruby\
**Created:** [September 9, 2010, 4:43pm UTC](https://www.ruby-forum.com/t/regex-help-please/194726 "2010-09-09T16:43:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 9, 2010, 4:43pm UTC](https://www.ruby-forum.com/t/regex-help-please/194726/1 "2010-09-09T16:43:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 9, 2010, 5:01pm UTC](https://www.ruby-forum.com/t/regex-help-please/194726/2 "2010-09-09T17:01:37Z")

</div>

-----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/](http://enigmail.mozdev.org/)

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

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 9, 2010, 8:23pm UTC](https://www.ruby-forum.com/t/regex-help-please/194726/3 "2010-09-09T20:23:44Z")

</div>

Marvin GÃ¼lker wrote:

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

works for me. many thanks!

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 10, 2010, 1:45am UTC](https://www.ruby-forum.com/t/regex-help-please/194726/4 "2010-09-10T01:45:07Z")

</div>

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/](http://www.ruby-forum.com/).

irb\> [“a”, “b”, “c”, “a”, “d”, “c”].uniq  
=\> [“a”, “b”, “c”, “d”]

-Rob

Rob B.  
removed\_email\_address@domain.invalid [http://AgileConsultingLLC.com/](http://AgileConsultingLLC.com/)  
removed\_email\_address@domain.invalid [http://GaslightSoftware.com/](http://GaslightSoftware.com/)

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 10, 2010, 4:43pm UTC](https://www.ruby-forum.com/t/regex-help-please/194726/5 "2010-09-10T16:43:45Z")

</div>

> irb\> [“a”, “b”, “c”, “a”, “d”, “c”].uniq

Thanks Rob! Works like a charm.

Joe

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 9, 2010, 10:52pm UTC](https://www.ruby-forum.com/t/regex-help-please/194726/6 "2010-09-09T22:52:16Z")

</div>

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"
