[cmake-developers] [CMake 0015807]: Regex does not match last parenthesis if parenthesis is part of character set.

Mantis Bug Tracker mantis at public.kitware.com
Thu Oct 22 08:45:40 EDT 2015


The following issue has been SUBMITTED. 
====================================================================== 
https://cmake.org/Bug/view.php?id=15807 
====================================================================== 
Reported By:                maarten
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15807
Category:                   (No Category)
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2015-10-22 08:45 EDT
Last Modified:              2015-10-22 08:45 EDT
====================================================================== 
Summary:                    Regex does not match last parenthesis if parenthesis
is part of character set.
Description: 
The aim is to extract the content between two parentheses.

Example:
from the string "FUNCTION(ARG1, ARG2, ARG3) //COMMENT",
I want to extract "ARG1, ARG2, ARG3".

The normal behavior of CMake is to return all the matched characters.
In the case of a paranthesis as matched character, it does not return the
closing parenthesis.

For reference, I have added the expected behavior by replacing all parentheses
with underscores.

Steps to Reproduce: 
cmake_minimum_required(VERSION 3.3)

#Do the match with parentheses
string(REGEX MATCH "FUNCTION\(([^\)]+)\)" ARGUMENT "FUNCTION(ARG1, ARG2, ARG3)
//COMMENT")
message(STATUS "Result of regex match with parentheses: ${ARGUMENT}")

#Redo the match with the parentheses replaced with underscores
string(REGEX MATCH "FUNCTION_([^_]+)_" ARGUMENT "FUNCTION_ARG1, ARG2, ARG3_
//COMMENT")

message(STATUS "Result of regex match with underscores: ${ARGUMENT}")

Additional Information: 
Output of the CMakeLists.txt:
-- The C compiler identification is GNU 5.1.1
-- The CXX compiler identification is GNU 5.1.1
-- Check for working C compiler: /usr/lib64/ccache/cc
-- Check for working C compiler: /usr/lib64/ccache/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++
-- Check for working CXX compiler: /usr/lib64/ccache/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Result of regex match with parentheses: FUNCTION(ARG1, ARG2, ARG3
-- Result of regex match with underscores: FUNCTION_ARG1, ARG2, ARG3_
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp

The result of the regex match with parentheses should be
FUNCTION(ARG1, ARG2, ARG3)
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-10-22 08:45 maarten        New Issue                                    
======================================================================



More information about the cmake-developers mailing list