Lab12 solutions (UCB CS61A@2021 Fall)
Regular Expressions
Q1: Calculator Ops
Write a regular expression that parses strings written in the 61A Calculator language and returns any expressions which have two numeric operands, leaving out the parentheses around them.
We need to write a regular expression to match a pattern - (operand operator1 operator2). The operands consist of +, -, *, /. We can use [] here. Don’t forget to put a \ in front of - to escape it.