# Regular Expression pattern

**URL:** <https://www.ruby-forum.com/t/regular-expression-pattern/89602>\
**Category:** Rails\
**Created:** [March 21, 2007, 3:27pm UTC](https://www.ruby-forum.com/t/regular-expression-pattern/89602 "2007-03-21T15:27:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![selvaraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@selvaraj](https://www.ruby-forum.com/u/selvaraj)\
**Post date:** [March 21, 2007, 3:27pm UTC](https://www.ruby-forum.com/t/regular-expression-pattern/89602/1 "2007-03-21T15:27:50Z")

</div>

Hai

```
I am trying one small pattern . but it giviong lot of problem.

```

For example I am getting string like “Hai I an fine 11111 22222 2222  
33333”

from this i want only integer part.like this ‘11111 22222 2222 33333’

i am using str=~/\s\d+$/, But i am getting only first part like ‘1111’.  
i want all the digit part.

regards  
Selvaraj

---

<div class="post-metadata">

**Author:** ![selvaraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@selvaraj](https://www.ruby-forum.com/u/selvaraj)\
**Post date:** [March 21, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/regular-expression-pattern/89602/2 "2007-03-21T15:44:36Z")

</div>

You probably want a character class:  
/[\s\d]+$/

… to check for any number of spaces or digits in a row.

I didn’t test this (and I don’t use regex often) but hopefully this  
points you in the right direction.

– Wes

---

<div class="post-metadata">

**Author:** ![selvaraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@selvaraj](https://www.ruby-forum.com/u/selvaraj)\
**Post date:** [March 21, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/regular-expression-pattern/89602/3 "2007-03-21T15:58:23Z")

</div>

ya very many thanks…

its working fine

wesgarrison wrote:

> You probably want a character class:  
> /[\s\d]+$/
> 
> … to check for any number of spaces or digits in a row.
> 
> I didn’t test this (and I don’t use regex often) but hopefully this  
> points you in the right direction.
> 
> – Wes

---

<div class="post-metadata">

**Author:** ![selvaraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@selvaraj](https://www.ruby-forum.com/u/selvaraj)\
**Post date:** [March 21, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/regular-expression-pattern/89602/4 "2007-03-21T17:19:52Z")

</div>

On Wed, 21 Mar 2007 15:27:50 +0100  
selvaraj [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i am using str=~/\s\d+$/, But i am getting only first part like  
> ‘1111’. i want all the digit part.
> 
> regards  
> Selvaraj

For that to work, you need to do some grouping with () in your regexp.

/(\s\d)+/ will get you any sequence of digits and spaces.

/(\s\d+)+/ will get you any number of sequences of a space followed by  
any number of digits.

–  
Jamie
