# Regexp to extra a all numbers

**URL:** <https://www.ruby-forum.com/t/regexp-to-extra-a-all-numbers/124046>\
**Category:** Ruby\
**Created:** [December 24, 2007, 2:03am UTC](https://www.ruby-forum.com/t/regexp-to-extra-a-all-numbers/124046 "2007-12-24T02:03:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![agorilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@agorilla](https://www.ruby-forum.com/u/agorilla)\
**Post date:** [December 24, 2007, 2:03am UTC](https://www.ruby-forum.com/t/regexp-to-extra-a-all-numbers/124046/1 "2007-12-24T02:03:36Z")

</div>

I’m trying to get an array of every number in a string that is grouped  
together. This is the code I thought might do it, but does not:

irb(main):064:0\> “923 a 222”.match(/\d+/).to\_a  
=\> [“923”]

I’m sure there’s a simple way to do this, but I’m not that well versed  
with Regular Expressions.

The results I was expected (and the results that are desired) are:

[“923”, “222”]

Thanks in advance for any help.

---

<div class="post-metadata">

**Author:** ![agorilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@agorilla](https://www.ruby-forum.com/u/agorilla)\
**Post date:** [December 24, 2007, 2:14am UTC](https://www.ruby-forum.com/t/regexp-to-extra-a-all-numbers/124046/2 "2007-12-24T02:14:13Z")

</div>

Bill G. wrote:

> [“923”, “222”]
> 
> Thanks in advance for any help.

You’re very close. Try this

“923 a 222”.scan(/\d+/)

---

<div class="post-metadata">

**Author:** ![agorilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@agorilla](https://www.ruby-forum.com/u/agorilla)\
**Post date:** [December 24, 2007, 2:31am UTC](https://www.ruby-forum.com/t/regexp-to-extra-a-all-numbers/124046/3 "2007-12-24T02:31:26Z")

</div>

Excellent. Thanks so much Tim.

Tim H. wrote:

> Bill G. wrote:
> 
> > [“923”, “222”]
> > 
> > Thanks in advance for any help.
> 
> You’re very close. Try this
> 
> “923 a 222”.scan(/\d+/)
