Link to home
Start Free TrialLog in
Avatar of Lee5
Lee5

asked on

Matching only numbers

What is the pattern to match only numbers
ie;
a$ = "Yes" if(b$ contains only numbers);
ASKER CERTIFIED SOLUTION
Avatar of HalldorG
HalldorG
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of martinag
martinag

$a = 'Yes' if $b =~ m/^\d*$/g;

Martin
Actually, that will treat an empty string as a number. If you don't want that, simply replace * with +.

Martin
Furthermore, what it the number is

7.0e6

There's a FMTYEWTK about this on the perl.com site. I generallly do

sub IsNumber {
    local($^W) = 0;
    my($a) = shift;
    return 0 if !defined($a);
    $a = s/^\s+|\s+$//;
    return 0 if $a eq '';
    return $a == $a + 0;
}

    return $a == $a + 0;

>> FMTYEWTK
What would that be in plain english?

Martin
Avatar of Lee5

ASKER

Also thanks to b2pi and martinag
Far More Than You Ever Wanted To Know

(Like FAQ, but Not so Frequent :))