[cmake-developers] regex replace bug?
Matthew Woehlke
matthew.woehlke at kitware.com
Tue Oct 30 17:45:54 EDT 2012
While writing a command to invoke asciidoc, I thought I would use this
little regex replace to get the output file name:
string(REGEX REPLACE "([.][^.]+)?$" ".html" BAR "${FOO}")
However, CMake is throwing this error:
string sub-command REGEX, mode REPLACE regex "([.][^.]+)?$" matched an
empty string.
This doesn't seem right for two reasons:
1. The match (given an input 'foo.txt') should have been non-empty.
2. Even if the match is empty, the use of an anchor makes it definite
and non-ambiguous, so replacement should succeed.
For point 2, I get a similar error if the match is '^' or '$', both of
which I would have expected to be valid. (Silly perhaps if/when the
expression is known when writing the replace rule, as using a regex
replace is overkill for such a case, but still valid.)
For comparison, doing the replace with sed using the same expression
works as expected (i.e. { 'foo', 'foo.txt' } -> 'foo.html'). In
particular, while sed is understandably unhappy being asked to match and
replace '' (empty pattern), '^' and '$' are both valid.
Is this expected behavior, or should I file a bug?
(And yes, I'm now using get_filename_component, but still...)
--
Matthew
More information about the cmake-developers
mailing list