Regular Expression pattern

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

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

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

On Wed, 21 Mar 2007 15:27:50 +0100
selvaraj [email protected] 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