Bug report: same regex and input string, different results in `string(REGEX MATCH ...)` and `string(REGEX REPLACE ...)`
Observed behavior:
Using CMake 3.13.1, with the SAME INPUT STRING, and SAME REGEX SPECIFICATION STRING (match-regex), string(REGEX MATCH ...)
is matching the expected substring, but string(REGEX REPLACE ...)
is giving a warning that it only matched the empty string.
Expected behavior:
string(REGEX REPLACE ...
will match the same portion of the (identical) input text, using the same regular expression, and perform the substitution.
MCVE:
Here is a minimally complete verifiable example:
cmake_minimum_required(VERSION 3.13.1)
set(MY_STRING "1;2;4;8;16
2;4;9;18;38
")
message(STATUS "MY_STRING = ${MY_STRING}")
string(REGEX MATCH "^[^\n]*" FIRST_LINE "${MY_STRING}")
message(STATUS "FIRST_LINE = ${FIRST_LINE}")
message(STATUS "MY_STRING = ${MY_STRING}")
string(REGEX REPLACE "^[^\n]*" "" REST "${MY_STRING}")
message(STATUS "REST = ${REST}")
And here is the output it yields:
-- MY_STRING = 1;2;4;8;16
2;4;9;18;38
-- FIRST_LINE = 1;2;4;8;16
-- MY_STRING = 1;2;4;8;16
2;4;9;18;38
CMake Error at CMakeLists.txt:9 (string):
string sub-command REGEX, mode REPLACE: regex "^[^
]*" matched an empty string.
-- REST =
-- Configuring incomplete, errors occurred!