MantisBT - CMake
View Issue Details
0011370CMakeCMakepublic2010-10-27 08:062011-06-06 18:25
Dmitry Kuzmenko 
David Cole 
normalminoralways
closedno change required 
CMake-2-8 
CMake 2.8.4 
0011370: There is no way to specify ] in [ ] list in regular expressions
I've tried to compile regular expression matches any string, ends with
set of symbols, including right square bracket (']', '}' and ')', for example). I've found no way to do that simple thing.

If I specify ".*[\]})]" cmake prints error:
Syntax error in cmake code at /home/dimm/test/test.cmake:3 when parsing string
.*[\]})] Invalid escape sequence \]

If I use ".*[\\]})]" it thinks I want to match a string ends with "\})]"
sequence.
No tags attached.
Issue History
2010-10-27 08:06Dmitry KuzmenkoNew Issue
2010-12-15 12:08David ColeAssigned To => David Cole
2010-12-15 12:08David ColeStatusnew => assigned
2011-02-03 19:34David ColeNote Added: 0025271
2011-02-03 19:35David ColeNote Added: 0025272
2011-02-03 19:35David ColeStatusassigned => resolved
2011-02-03 19:35David ColeFixed in Version => CMake 2.8.4
2011-02-03 19:35David ColeResolutionopen => no change required
2011-06-06 18:25David ColeStatusresolved => closed
2011-06-06 18:25David ColeNote Added: 0026701

Notes
(0025271)
David Cole   
2011-02-03 19:34   
This works for me:

# Enclose everything except for ']' in the '[...]' sequence, and then
# enclose that in an '(a|b)' construct, finally looking like:
# "([...]|])"

The following code:

set(regex ".*([>}\\)]|])$")

function(tryit s)
  if(s MATCHES "${regex}")
    message(STATUS " match: '${s}'")
  else()
    message(STATUS "NO match: '${s}'")
  endif()
endfunction()

tryit(" open [")
tryit("close ]")
tryit(" open {")
tryit("close }")
tryit(" open (")
tryit("close )")
tryit(" open <")
tryit("close >")

Yields this output:

-- NO match: ' open ['
-- match: 'close ]'
-- NO match: ' open {'
-- match: 'close }'
-- NO match: ' open ('
-- match: 'close )'
-- NO match: ' open <'
-- match: 'close >'
(0025272)
David Cole   
2011-02-03 19:35   
There is a way..... you just have to work out a different way than other regex engines many times. :-)

See the previous note for a way to match ']' as a "part" of a [...] character set.
(0026701)
David Cole   
2011-06-06 18:25   
Closing resolved issues that have not been updated in more than 3 months.