Question: ANSWER IN PYTHON Consider a simple arithmetic expression of the form operand operator operand (exactly two operands, and one operator) where the operands are either

ANSWER IN PYTHON

Consider a simple arithmetic expression of the form "operand operator operand" (exactly two operands, and one operator) where the operands are either variables or integer constants, and the operator is one of +, -, /, or *.

Variable names can only have letters (upper or lowercase), digits and underscores, but the first character cannot be a digit. There's no limit to the length of a variable name. Integer constants may have leading zeros. There may or may not be whitespaces around the operator, or around the entire expression.

Examples of legitimate expressions:

' 01*278 '

'_abc_1x2 +12'

Example of non-legit expressions:

'25/1ABC' (1ABCD is not a variable name, starts with digit)

'a & b' ('&' is not one of the 4 allowed operators)

'? a * 12 + 5 (extraneous stuff at beginning/end)

Write a regular expression to match and extract the operands and operator (in the order in which they appear) from this form of arithmetic expression. Assume that there will be a call re.findall that will apply your regular expression to a string.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!