Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread [EMAIL PROTECTED]
Neat! I didn't realize that re.sub could take a function as an argument. Thanks. Lorin -- http://mail.python.org/mailman/listinfo/python-list

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Lonnie Princehouse
> Is there some equivalent feature in Python regexps? cpp_pat = re.compile('(/\*.*?\*/)|(".*?")', re.S) def subfunc(match): if match.group(2): return match.group(2) else: return '' stripped_c_code = cpp_pat.sub(subfunc, c_code) ...I suppose this is what the Perl code might do, but

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Lonnie Princehouse
> Is there some equivalent feature in Python regexps? cpp_pat = re.compile('(/\*.*?\*/)|(".*?")', re.S) def subfunc(match): if match.group(2): return match.group(2) else: return '' stripped_c_code = cpp_pat.sub(subfunc, c_code) ...I suppose this is what the Perl code might do, but

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Jeff Epler
# import re, sys def q(c): """Returns a regular expression that matches a region delimited by c, inside which c may be escaped with a backslash""" return r"%s(\\.|[^%s])*%s" % (c, c, c) single_quoted_string = q('

Stripping C-style comments using a Python regexp

2005-07-27 Thread [EMAIL PROTECTED]
Hi Folks, I'm trying to strip C/C++ style comments (/* ... */ or // ) from source code using Python regexps. If I don't have to worry about comments embedded in strings, it seems pretty straightforward (this is what I'm using now): cpp_pat = re.compile(r""" /\* .*? \*/ |# C comm