Skip to content

string(REGEX REPLACE) anchoring fails

If you create the following test.cmake file:

set(test "whatever")
string(REGEX REPLACE "(^[^-])" "x" test "${test}")
message(STATUS "test = ${test}")

and execute it with

cmake -P test.cmake

the result "xxxxxxxx" is obtained rather than the expected "xhatever". In other words the result is the same as if the regular expression does not start with the anchor.

N.B. This is a long standing issue; I get the incorrect result both for CMake-3.0.2 and 3.8.1.

Edited by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information