[CMake] string(REGEX REPLACE …) syntax problem
David Cole
dlrdave at aol.com
Sat Mar 30 23:29:49 EDT 2013
REGEX REPLACE will replace "this" with "that" in the entire input
string, everywhere it matches. If you want to limit it to just the one
bit that matches inside the parenthesis, you have to match the entire
string, too, so that it will also be replaced. In your example, the \\1
is being set to "Release" and the "/build Release" is being replaced
with \\1 in the entire input string. So in effect, you erased the
"/build " from in front of it. What you want is to erase the whole
string, except for the "Release", right?
This should work:
> string(REGEX REPLACE "^.*/build ([A-Za-z]+).*$" "\\1" BUILD_CONFIG
${FOO})
I just added "^.*" at the beginning, and ".*$" at the end, so it
matches the entire input string.
Hope this helps,
David C.
-----Original Message-----
From: Braden McDaniel <braden at endoframe.com>
To: cmake <cmake at cmake.org>
Sent: Sat, Mar 30, 2013 11:10 pm
Subject: [CMake] string(REGEX REPLACE …) syntax problem
I must be Doing It Wrong; but I'm not seeing how...
If I do a REGEX MATCH as follows:
> build_command(FOO)
> string(REGEX MATCH "/build ([A-Za-z]+)" BUILD_CONFIG ${FOO})
> message(STATUS "BUILD_CONFIG = ${BUILD_CONFIG}")
... I get, as expected:
> BUILD_CONFIG = /build Release
However, if I use the same expression with REGEX REPLACE:
> build_command(FOO)
> string(REGEX REPLACE "/build ([A-Za-z]+)" "\\1" BUILD_CONFIG ${FOO})
> message(STATUS "BUILD_CONFIG = ${BUILD_CONFIG}")
... BUILD_CONFIG holds the entire build command line rather than just
the
configuration name:
> BUILD_CONFIG = C:\PROGRA~2\MICROS~1.0\Common7\IDE\devenv.com my.sln
Release
/project ALL_BUILD
How am I misapplying REGEX REPLACE?
--
Braden McDaniel
braden at endoframe.com
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
More information about the CMake
mailing list