# Re: How I can check number?

**URL:** <https://www.ruby-forum.com/t/re-how-i-can-check-number/95442>\
**Category:** Ruby\
**Created:** [June 1, 2006, 12:38pm UTC](https://www.ruby-forum.com/t/re-how-i-can-check-number/95442 "2006-06-01T12:38:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 1, 2006, 12:38pm UTC](https://www.ruby-forum.com/t/re-how-i-can-check-number/95442/1 "2006-06-01T12:38:11Z")

</div>

In einer eMail vom 01.06.2006 12:21:49 WesteuropÃ¤ische Normalzeit  
schreibt  
removed\_email\_address@domain.invalid:

How I can simplify it:  
params[:value] =~ /^\d+$|^-\d+$|^\d+.\d+$|^-\d+.\d+$/

OK, so, you want to extract the numbers that can by either floats or  
integers from some  
text.  
You can use a \* after something you don’t necessarily need in your  
Regexp,  
and you can  
use that on groups of characters, enclosed in brackets:

text=‘my bank account is -100000000.09 dollars, but I earn 1 dollar a  
day,  
which is better than earning 0.50 dollars or 0 dollars.’  
words=text.split  
numbers=[]  
words.each{|x|  
if x=~ /^-_\d+(.\d+)_$/  
numbers\<\<x  
end  
}  
p ‘all the numbers that were there:’  
p numbers

Best regards,

Axel
