View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0015807 | CMake | (No Category) | public | 2015-10-22 08:45 | 2016-03-07 09:12 | ||||
Reporter | maarten | ||||||||
Assigned To | |||||||||
Priority | normal | Severity | minor | Reproducibility | always | ||||
Status | closed | Resolution | no change required | ||||||
Platform | Linux | OS | Fedora Linux | OS Version | 22 | ||||
Product Version | CMake 3.3.2 | ||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0015807: 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) | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | |||||||||
Relationships | |
Relationships |
Notes | |
(0039670) maarten (reporter) 2015-10-22 09:17 |
I could get it working by double escaping the backslash. Why is this? 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 parenthesis: ${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}") |
(0039671) Brad King (manager) 2015-10-22 09:19 |
You need another layer of backslashes to get through the CMake quoted argument syntax: string(REGEX MATCH "FUNCTION\\(([^)]+)\\)" ARGUMENT "FUNCTION(ARG1, ARG2, ARG3) //COMMENT") Or you can use a bracket argument in CMake 3.0 and above: string(REGEX MATCH [[FUNCTION\(([^)]+)\)]] ARGUMENT "FUNCTION(ARG1, ARG2, ARG3) //COMMENT") |
(0040625) Robert Maynard (manager) 2016-03-07 09:12 |
Closing resolved issues that have not been updated in more than 4 months. |
Notes |
Issue History | |||
Date Modified | Username | Field | Change |
2015-10-22 08:45 | maarten | New Issue | |
2015-10-22 09:17 | maarten | Note Added: 0039670 | |
2015-10-22 09:19 | Brad King | Note Added: 0039671 | |
2015-10-22 09:19 | Brad King | Status | new => resolved |
2015-10-22 09:19 | Brad King | Resolution | open => no change required |
2016-03-07 09:12 | Robert Maynard | Note Added: 0040625 | |
2016-03-07 09:12 | Robert Maynard | Status | resolved => closed |
Issue History |
Copyright © 2000 - 2018 MantisBT Team |