View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0011370CMakeCMakepublic2010-10-27 08:062011-06-06 18:25
ReporterDmitry Kuzmenko 
Assigned ToDavid Cole 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product VersionCMake-2-8 
Target VersionFixed in VersionCMake 2.8.4 
Summary0011370: There is no way to specify ] in [ ] list in regular expressions
DescriptionI'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.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0025271)
David Cole (manager)
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 (manager)
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 (manager)
2011-06-06 18:25

Closing resolved issues that have not been updated in more than 3 months.

 Issue History
Date Modified Username Field Change
2010-10-27 08:06 Dmitry Kuzmenko New Issue
2010-12-15 12:08 David Cole Assigned To => David Cole
2010-12-15 12:08 David Cole Status new => assigned
2011-02-03 19:34 David Cole Note Added: 0025271
2011-02-03 19:35 David Cole Note Added: 0025272
2011-02-03 19:35 David Cole Status assigned => resolved
2011-02-03 19:35 David Cole Fixed in Version => CMake 2.8.4
2011-02-03 19:35 David Cole Resolution open => no change required
2011-06-06 18:25 David Cole Status resolved => closed
2011-06-06 18:25 David Cole Note Added: 0026701


Copyright © 2000 - 2018 MantisBT Team