in reply to how would you detect a math expression
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.
|
|---|