I am trying to use regex to match bracketed text. It seems that cmake doesn’t like when I try to exclude a ‘]’ in middle.
I tested my regex here and it works as expected. I thought it would work for cmake as well. As far as I can tell, I am not using any features that cmake does not support.
function(print_var var)
message(STATUS "${var} = ${${var}}")
endfunction()
set(text "[bracketed text]" )
# this is the pattern I really want
set(pattern "^\\[(([^ \\[\\]\t\r\n]+)( *([^ \\[\\]\t\r\n]+))*)\\]$")
string(REGEX MATCH "${pattern}" output "${text}")
print_var(pattern)
print_var(text)
print_var(output)
print_var(CMAKE_MATCH_1)
# this works but allows ']' in middle of the text
set(pattern "^\\[(([^ \\[\t\r\n]+)( *([^ \\[\t\r\n]+))*)\\]$")
string(REGEX MATCH "${pattern}" output "${text}")
print_var(pattern)
print_var(text)
print_var(output)
print_var(CMAKE_MATCH_1)
# https://regex101.com/r/RzHF72/1