Irbis
Irbis

Reputation: 13369

cmake - error in compile regular expression

I have a string: 1.0.2-1 and I need to get a substring: 1.0.2 Following regular expression works fine in c++:

std::regex myReg(".+?(?=-)");

When I try to use that regex in cmake:

STRING(REGEX MATCH ".+?(?=-)" OUTPUT $VER)

I get errors:

[INFO] RegularExpression::compile(): Nested *?+.
[INFO] RegularExpression::compile(): Error in compile.

How to fix that ?

Upvotes: 2

Views: 3733

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626799

CMake regex syntax does not support lazy quantifiers, hence the error message.

Since you need to get the first match with characters other than -, you can use

[^-]+

Or (to tell the engine to only look for a match from the beginning of the string):

^[^-]+

Upvotes: 2

Related Questions