Stripping C-style comments using a Python regexp
Lonnie Princehouse
finite.automaton at gmail.com
Wed Jul 27 12:50:05 EDT 2005
> 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 I'm not sure,
since trying to read it hurts my brain...
More information about the Python-list
mailing list