extract c/cpp include file with regular expression

tiefeng wu icebergwtf at gmail.com
Thu Jul 23 12:21:41 EDT 2009


MRAB wrote:
> I'd probably do:
>
>>>> p = re.compile(r'#\s*include\s+(?:<([^>]*)>|"([^"]*)")')
>>>> m = p.search('#include <header.h>')
>>>> m.group(1) or m.group(2)
> 'header.h'
>

yes, it's easier to understand.
thanks, MRAB!
I always make things complicated :P

tiefeng wu
2009-07-23



More information about the Python-list mailing list