RegEx for matching brackets
NevilleDNZ
nevillednz at gmail.com
Sat May 3 21:38:46 EDT 2008
To check a complete python expression use:
def check_open_close(expr):
try:
eval(expr)
except SyntaxError:
return False
else:
return True
This also ignores brackets in quotes, and checks <= & >= operators are
syntatically correct etc...
But is may have side effects... ;-)
eg.
check_open_close('__import__("os").system("echo rm -rf /") # OK')
c.f http://en.wikipedia.org/wiki/Scope_creep
N
More information about the Python-list
mailing list