STRING(REGEX REPLACE) sets CMAKE_MATCH_# so that next regex cannot clear it.
Correct behavior: regex-like commands with capture groups set CMAKE_MATCH_# variables for each group. When such a group matches an empty string, the respective variable is also set to empty.
Issue encountered: STRING(REGEX REPLACE) that sets a CMAKE_MATCH_# variable somehow prevents other commands to access this variable: a consecutive regex match whose capture group for that variable is empty will not clear the variable, instead the result of the REGEX REPLACE is kept.
This bug is not triggered by other regex commands (I tried STRING(REGEX MATCH ...) and IF(... MATCHES ...)), only STRING(REGEX REPLACE)
Please see this minimal code snippet.
CMake version used is 3.8.1