CMP0186
Added in version 4.1.
Regular expressions match ^ at most once in repeated searches.
This policy affects commands that perform multiple regular expression searches:
and the generator expression $<LIST:TRANSFORM,list,REPLACE>.
CMake 4.0 and below match the ^ anchor at the start of every successive search, leading to multiple matches:
string(REGEX REPLACE "^a" "b" result "aaaa") # result="bbbb" string(REGEX MATCHALL "^a" result "aaaa") # result="a;a;a;a"
CMake 4.1 and above prefer to match the ^ anchor at most once, at the start of the input string:
string(REGEX REPLACE "^a" "b" result "aaaa") # result="baaa" string(REGEX MATCHALL "^a" result "aaaa") # result="a"
This policy provides compatibility for projects that have not been updated.
The OLD behavior for this policy is to match ^ multiple times, at the start of each search. The NEW behavior for this policy is to match ^ at most once, at the start of the input string.
This policy was introduced in CMake version 4.1. It may be set by cmake_policy() or cmake_minimum_required(). If it is not set, CMake does not warn, and uses OLD behavior.
Note
The OLD behavior of a policy is deprecated by definition and may be removed in a future version of CMake.
© 2000–2026 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/latest/policy/CMP0186.html