diff --git a/lib/DDG/Goodie/Conversions.pm b/lib/DDG/Goodie/Conversions.pm index 2d0d477cc..6e2f755e3 100755 --- a/lib/DDG/Goodie/Conversions.pm +++ b/lib/DDG/Goodie/Conversions.pm @@ -93,7 +93,7 @@ handle query_lc => sub { return unless scalar @matches == 2; # conversion requires two triggers # normalize the whitespace, "25cm" should work for example - $_ =~ s/([0-9])([a-df-zA-DF-Z])/$1 $2/; # Skip 'e' to handle exponentials. + $_ =~ s/($number_re)($keys)/$1 $2/g; # fix precision and rounding: my $precision = 3; diff --git a/lib/DDG/GoodieRole/NumberStyler.pm b/lib/DDG/GoodieRole/NumberStyler.pm index 1b6461584..46048953e 100644 --- a/lib/DDG/GoodieRole/NumberStyler.pm +++ b/lib/DDG/GoodieRole/NumberStyler.pm @@ -28,10 +28,12 @@ my @known_styles = ( # This is not as good an idea as I might think. # Luckily it will someday be able to be tokenized so this won't apply. -my $all_seps = join('', map { $_->decimal . $_->thousands . $_->exponential } @known_styles); +my $all_seps = join('', map { $_->decimal . $_->thousands } @known_styles); +my $numbers = '[\d' . $all_seps . ']+'; +my $re_text = join('|', $numbers, map { $numbers . $_->exponential . '\d+' } @known_styles); sub number_style_regex { - return qr/[\d$all_seps]+/; + return qr/$re_text/; } # Takes an array of numbers and returns which style to use for parse and display