Skip to content

regex: Match ^ at most once in repeated searches

Nikita Nemkin requested to merge nnemkin/cmake:regex into master

When doing successive matches, track the input start and current search start positions separately to prevent the ^ anchor from matching in the middle of the string. Add policy CMP0186 to provide compatibility.

Original Description

String REGEX REPLACE and REGEX MATCHALL don't distinguish between input start and match start position, resulting in ^ matching at the start of every successive match. E.g. MATCHALL "^0" "0000" matches every zero and produces "0;0;0;0" instead of "0".

This change separates the match start from the input start and ^ correctly matches only at the input start.

MATCHALL with an anchor doesn't really make sense and could be left out, but I believe it's best to fix both commands for correctness and consistency.

Two CMake tests (testList and RegexMultiMatchClear) and CPack test harness assumed the old behavior and had to be fixed. I've added a separate test for new behavior.

Issue: #26629 (closed)
Fixes: #16899 (closed)

Edited by Brad King

Merge request reports

Loading