Multiple/"global" regex matching matches starting anchor (^) patterns for non-first matches
Take a look at this Stack Overflow question and my answer post there.
Example of the unexpected behaviour:
set(in 12345 12345a 12345ab 12345abc 12345abcd 12345abcde)
list(TRANSFORM in REPLACE "^....." "" OUTPUT_VARIABLE out)
message("${out}")
# output: ;a;ab;abc;abcd;
Quoting from my answer to the Stack Overflow question:
So the hypothesis is: when CMake tries to execute a regex more times, it starts from after what it last matched, and forgets to take into consideration any anchor constraints like
^. Taking a look at the code in cmStringReplaceHelper.cxx, I find it suspect:bool cmStringReplaceHelper::Replace(const std::string& input, std::string& output) { output.clear(); // Scan through the input for all matches. std::string::size_type base = 0; while (this->RegularExpression.find(input.c_str() + base)) { ...There doesn't seem to be any info to tell
RegularExpression.findabout the fact that there was previous content to the input string it's being passed, which would be pertinent to it knowing whether what it's given is really the start of the input.
Is this by design? Or is it a bug?