in reply to how would you detect a math expression

I've never tried Google calculator, but it doesn't seem like it should be too difficult to detect at least fairly simple math expressions.

Something like:

# Assuming expression is in $string my $num = '-?(\.\d+|\d+(\.\d+)?)'; my $ops = '[-+*/]'; if ($string =~ /^(${num}${ops})+${num})$/) { # It's a simple math calculation } else { # It's something else }

Now that's pretty basic, but it should parse expressions of the form number op number [op number ...] for numbers containing an optional leading "-", and at least one digit (with possible decimal point), and for any of the basic operations {+, -, *, /}.

For anything more complicated than that, you'll have to ask someone with a more intimate knowledge of Google calculator than I.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/