I am thinking of validating an infix notation which consists of alphabets as operands and +-*/$ as operators [eg: A+B-(C/D)$(E+F)] using regex in Java. Is there any better way? Is there any regex pattern which I can use?
I am thinking of validating an infix notation which consists of alphabets as operands
Share
I am not familiar with the language syntax of
infix, but you can certainly do a first pass validation check which simply verifies that all of the characters in the string are valid (i.e. acceptable characters =A-Z,+,-,*,/,$,(and)). Here is a Java program which checks for valid characters and also includes a function which checks for unbalanced (possibly nested) parentheses:This does not validate the grammar, but may be useful as a first test to filter out obviously bad strings.