I have the following code:
def commandType(self):
import re
print self.cmds[self.counter]
if re.match("@",self.cmds[self.counter]):
return Parser.A_COMMAND
elif re.match('(',self.cmds[self.counter]):
return Parser.L_COMMAND
else:
return Parser.C_COMMAND
and on this line: elif re.match('(',self.cmds[self.counter]):
I'm getting an error.
What am I doing wrong?
Parentheses have special meaning in regular expressions. You can escape the paren but you really do not need a regex at all for this problem:
def commandType(self):
print self.cmds[self.counter]
if '@' in self.cmds[self.counter]):
return Parser.A_COMMAND
elif '(' in self.cmds[self.counter]:
return Parser.L_COMMAND
else:
return Parser.C_COMMAND
The parenthesis '(' and ')' are used as grouping mechanism and scope operators in regexps. You have to escape them (and any other control symbols) via backslash, e.g. '\('.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With