CMake's regular expressions are relatively limited. Look at the static char* regatom (int *flagp)
method in RegularExpression.cxx. A \\
indicates that the next character is escaped (treated literally). It looks like there are no back-references possible in the CMake regex.
As a work around, you can invoke shell commands using execute_process
.
set(TEXT "ab,cc,df,gg")
message("TEXT: ${TEXT}")
execute_process(
COMMAND echo ${TEXT}
COMMAND sed "s/.*\\(\\(.\\)\\2\\).*/\\1/g"
OUTPUT_VARIABLE RESULT OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("RESULT: ${RESULT}")
This produces:
TEXT: ab,cc,df,gg
RESULT: gg
You will have to adjust your regex do produce cc;gg
from the given string.