From: Raul Parolari Date: 2007-11-23T09:54:51+09:00 Subject: Re: Checking whether a string is a number in disguise? Stefano Crocco wrote: > Alle gioved狸 22 novembre 2007... > In this case, you can either use Kernel#Float, which returns str.to_f > .. or try to craft a regexp which only matches strings containing > numbers. > For example, the (untested) regexp > > /[+-]?\d+(.\d+)?(e[+-]?\d+)?/ Two small additions: a) the 'dot' should be literally a dot (else it matches any character) b) the boundaries to the whole expresssion are needed (else "ab23.35de" would be validated). So, the regexp should be something like: /^ [+-]? \d+ (?: [.]\d+)? (?: e[+-]? \d+)? $ /x (If capture of components is desired, parenthesis should enclose all components, and the ?: removed). Raul -- Posted via http://www.ruby-forum.com/.