Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
CMake
CMake
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,296
    • Issues 3,296
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 9
    • Merge Requests 9
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #18690

Closed
Open
Created Dec 06, 2018 by Izaak Beekman@zbeekman

Bug report: same regex and input string, different results in `string(REGEX MATCH ...)` and `string(REGEX REPLACE ...)`

Observed behavior:

Using CMake 3.13.1, with the SAME INPUT STRING, and SAME REGEX SPECIFICATION STRING (match-regex), string(REGEX MATCH ...) is matching the expected substring, but string(REGEX REPLACE ...) is giving a warning that it only matched the empty string.

Expected behavior:

string(REGEX REPLACE ... will match the same portion of the (identical) input text, using the same regular expression, and perform the substitution.

MCVE:

Here is a minimally complete verifiable example:

cmake_minimum_required(VERSION 3.13.1)
set(MY_STRING "1;2;4;8;16
2;4;9;18;38
")
message(STATUS "MY_STRING = ${MY_STRING}")
string(REGEX MATCH "^[^\n]*" FIRST_LINE "${MY_STRING}")
message(STATUS "FIRST_LINE = ${FIRST_LINE}")
message(STATUS "MY_STRING = ${MY_STRING}")
string(REGEX REPLACE "^[^\n]*" "" REST "${MY_STRING}")
message(STATUS "REST = ${REST}")

And here is the output it yields:

-- MY_STRING = 1;2;4;8;16
2;4;9;18;38

-- FIRST_LINE = 1;2;4;8;16
-- MY_STRING = 1;2;4;8;16
2;4;9;18;38

CMake Error at CMakeLists.txt:9 (string):
  string sub-command REGEX, mode REPLACE: regex "^[^

  ]*" matched an empty string.


-- REST =
-- Configuring incomplete, errors occurred!
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None