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.
selvaraj (Guest)
on 2007-03-21 16: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
wesgarrison (Guest)
on 2007-03-21 16: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
selvaraj (Guest)
on 2007-03-21 16: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
Jamie M. (Guest)
on 2007-03-21 18:19
(Received via mailing list)
On Wed, 21 Mar 2007 15:27:50 +0100
selvaraj <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
This topic is locked and can not be replied to.