I have a string that looks something like this -
((COL1==VAL1)+(COL2==VAL2))
I want to convert this to following format:
((a.col1 == 'VAL1') & (a.col2 == 'VAL2'))
Another example -
From:
((COL1==VAL1)|(COL2==VAL2/A))
TO: ((a.col1 == 'VAL1') | (a.col2 == 'VAL2/A'))
can someone help please?
Code:
word = Word(alphas + alphanums + "+-_<> ")
open = Literal('(')
close = Literal(')')
single_quote = Literal('\'')
and_ = Literal('+')
equal = Literal('=')
comma = Literal(',')
or_ = Literal('|')
right_hand_value = word
left_hand_value = word
func = OneOrMore(open) + left_hand_value + OneOrMore(equal) + right_hand_value + OneOrMore(close)
results = func.parseString(string)
This kind of works only for one expression: (a.col1 == 'VAL1'). but I want this to handle multiple expressions.