Forum: Ruby on Rails Regular Expression pattern

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0b119a0054ac02e180950a8d247a4fbe?d=identicon&s=25 selvaraj (Guest)
on 2007-03-21 15:27
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
A332dcb1e051f733dc9a9bd78df3b560?d=identicon&s=25 wesgarrison (Guest)
on 2007-03-21 15:44
(Received via mailing list)
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
0b119a0054ac02e180950a8d247a4fbe?d=identicon&s=25 selvaraj (Guest)
on 2007-03-21 15:58
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
5c2285f675ad99d67216b8d4f547ac8a?d=identicon&s=25 Jamie Macey (Guest)
on 2007-03-21 17:19
(Received via mailing list)
On Wed, 21 Mar 2007 15:27:50 +0100
selvaraj <rails-mailing-list@andreas-s.net> 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
This topic is locked and can not be replied to.