[CMake] Regular Expression to filter out C/C++ Comments

Tyler Roscoe tyler at cryptio.net
Mon Feb 22 11:29:08 EST 2010


On Mon, Feb 22, 2010 at 04:28:54PM +0100, Andreas Lubensky wrote:
> i'm having some trouble building a regular expression to filter out C
> and C++ style comments (//... /*...*/).  I constructed various regular
> 
> "((/\\*([^\\*]|(\\*+([^\\*/])))*\\*+/)|(//[^\r\n]*))"

I don't think RE are the right tool for this job. You probably want a
little state machine instead (something like 'while (token != '*/') {
skip_token() }).

Why are you trying to do this? Can you do the parsing in a "real"
scripting language instead of in CMake?

tyler


More information about the CMake mailing list