PDA

View Full Version : Parsing a Qt Projectfile using regular expressions



MBex
1st November 2012, 10:08
Hello,

i am trying to parse the HEADERS and SOURCES section of a Qt project file.
Given the following content:




SOURCES += \
../Source/Test1.cpp \
../Source/Test2.cpp \

win32 {
SOURCES += \
../Source/Test.cpp
}



When searching with a regular expression, the matched result should be this:

SOURCES += \
../Source/Test1.cpp \
../Source/Test2.cpp \

The other SOURCES block should not be part of the result, cause it is wrapped in a {} block.

My base expression, which will match both is this, it works fine for the tests i have done.



SOURCES\s+(\+=|=)(\s+(.+\.cpp)?\s*\\?){0,}


Then i tried to exclude the second block by appending



\s*(?!\})


but this did not work as expected (changed nothing).

I am testing the expression using this side http://gskinner.com/RegExr/

Does anyone have an idea why this does not work?