Regex replace help

Richard Shaw hobbes1069 at
Sun Dec 4 19:26:57 UTC 2011

On Sun, Dec 4, 2011 at 9:20 AM, Haïkel Guémar <karlthered at> wrote:
> AFAIK, CMake does not have multi-line regex, so it doesn't work. If you
> find a better trick, please share it :-]

Denis's email client replied to the list and me and I didn't catch
that gmail only replied to him directly so there was a bit of an
exchange that was off list. Here's the reult:

I got it working but I'm not entirely happy with how I had to do it.

Here's the final code:

       string(REGEX MATCH "const int TIXML_MAJOR_VERSION = ([0-9]+);"
_TMP_major "${_contents}")
       string(REGEX REPLACE ".*([0-9]+).*" "\\1" _OUT_major "${_TMP_major}")
       string(REGEX MATCH "const int TIXML_MINOR_VERSION = ([0-9]+);"
_TMP_minor "${_contents}")
       string(REGEX REPLACE ".*([0-9]+).*" "\\1" _OUT_minor "${_TMP_minor}")
       string(REGEX MATCH "const int TIXML_PATCH_VERSION = ([0-9]+);"
_TMP_patch "${_contents}")
       string(REGEX REPLACE ".*([0-9]+).*" "\\1" _OUT_patch "${_TMP_patch}")

I think it was the lines ending with a semi-colon that was causing the
problem. Apparently ".*" doesn't match that. I still don't know why it
mas matching the entire file up to the correct line...

Thanks all!


More information about the devel mailing list