in reply to how would you detect a math expression

  1. Detect whether there are only acceptable characters
  2. Use a parser. I built a simple one, easy done (and customizable) without any modules, in Operator Precedence Parser.

As an extra, you can use it to calculate the value of the expression, though, if it parses, you can most likely safely use eval — it depends on what you accept as input.

  • Comment on Re: how would you detect a math expression