I'm trying to match recursive pattern in python but i'm missing something and getting errors.
I want to achieve:
var = [a-z]+
digit = [0-9]+
op=+,-,*,/
E->var|digit|op E E
eg:
"+ x 1",
"* x * y + x y"
This is my code:
import re
term="[a-z]+|[0-9]+"
op=[+-/*]
exp="("+term+"|("+op+" "+term+" "+term+")|(?R))
sow when I do re.match(exp,"+ x 1"), I'm getting :
"sre_constants.error: unexpected end of pattern"
Can anyone help me with this problem?
remodule doesn't have a recursion feature, if you need it, install and use theregexmodule. pypi.python.org/pypi/regex+")|(?R))be terminated with a double quote? As for the recursion, I don't see any nesting, are you just testing recursion for it's own sake?(?:[-+/*]*\s*(?:[a-z]+|[0-9]+)\s*|\s*(?:[-+/*]\s+(?:[a-z]+|[0-9]+)\s+(?:[a-z]+|[0-9]+))+)+will work for you without recursion?