Re: RegEx for matching brackets

2008-05-03 Thread NevilleDNZ
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. c

Re: RegEx for matching brackets

2008-05-02 Thread Derek Martin
On Fri, May 02, 2008 at 03:51:16PM -0700, NevilleDNZ wrote: > Thanx for the link to these parsers. ANTLR looks interesting. > Yoyo: http://www-users.cs.york.ac.uk/~fisher/software/yoyovwg/readme > > I figured out a way to do it in python. [...] > > def check_open_close(str): > try: > eval("

Re: RegEx for matching brackets

2008-05-02 Thread NevilleDNZ
On May 2, 11:13 am, George Sakkis <[EMAIL PROTECTED]> wrote: > [1]http://en.wikipedia.org/wiki/Context-free_language > [2]http://en.wikipedia.org/wiki/Regular_language > [3]http://wiki.python.org/moin/LanguageParsing Thanx for the link to these parsers. ANTLR looks interesting. Yoyo: http://www-us

Re: RegEx for matching brackets

2008-05-01 Thread George Sakkis
On May 1, 7:44 pm, NevilleDNZ <[EMAIL PROTECTED]> wrote: > Below is a (flawed) one line RegEx that checks curly brackets (from > awk/c/python input) are being matched. Is there a one liner for doing > this in python? There is not even a 1000-liner regular expression for this; it's a context-free

Re: RegEx for matching brackets

2008-05-01 Thread John Machin
On May 2, 9:44 am, NevilleDNZ <[EMAIL PROTECTED]> wrote: > Below is a (flawed) one line RegEx that checks curly brackets (from > awk/c/python input) are being matched. Is there a one liner for doing > this in python? > > ThanX > N > > re_open_close="(((\{))[^{}]*((?(0)\})))+" > re_open_close=re.co

RegEx for matching brackets

2008-05-01 Thread NevilleDNZ
Below is a (flawed) one line RegEx that checks curly brackets (from awk/c/python input) are being matched. Is there a one liner for doing this in python? ThanX N re_open_close="(((\{))[^{}]*((?(0)\})))+" re_open_close=re.compile(re_open_close) tests=""" { this is a test BAD { this is a test