[cmake-developers] regex bug?

Matthew Woehlke matthew.woehlke at kitware.com
Thu Dec 13 13:38:34 EST 2012


Consider this line of CMake code:

string(REGEX REPLACE "^([^.]*)(\..*)?$" "\1" BAR "${FOO}")

It looks reasonable to me, and works fine on !Windows. However, on 
Windows, I get these errors:

Syntax error in cmake code at <elided> when parsing string
^([^.]*)(\..*)?$
Invalid escape sequence \.

Syntax error in cmake code at <elided> when parsing string
\1
Invalid escape sequence \1


Is this expected? The documentation doesn't seem to explicitly mention 
replacement placeholders, but they are implicitly mentioned when talking 
about () capturing.

Also, I can use "^([^.]*)([.].*)?$" instead to get around the first 
error, but then I get an error that the capture is empty. (It shouldn't 
be; "${FOO}" is non-empty and the pattern is guaranteed to have a 
non-ambiguous match for non-empty input.)

-- 
Matthew




More information about the cmake-developers mailing list