I am currently trying to create a calculator API using ExpressJs. My problem is using regex as routes to determine common patterns.
A valid typical route is api/calculator/:operator/:number1/:number2 where by operator is a mathematical operator in a string format (add, subtract, multiply, divide) and number1 and number2 are operands.
My aim is, if any number is missed in the route, e.g api/calculator/:operator/:number1/, or api/calculator/:operator//:number2 or api/calculator/:operator// I want to send a response that the operands are invalid.
Also, if the operator is not valid, a response needs to be sent as a well.
How can I use regex to determine if the route is a valid one?