Check if a String is a Mathematical Expression

Published by zachiah in

Create a function that takes an input (e.g. "5 + 4") and returns true if it's a mathematical expression or false if not.

Examples

math_expr?("4 + 5") ➞ true

math_expr?("4*6") ➞ true

math_expr?("4*no") ➞ false

Notes

  • Should only work with the following operations: +, -, *, /, %
  • You don't need to test for floats.
  • int1 and int2 will only be from 0-9.
Watch a quick demo on how Edabit works.