[CMake] Regex Matching

Nils Gladitz nilsgladitz at gmail.com
Wed Aug 23 16:27:36 EDT 2017


On 23.08.2017 22:21, Andrew Bell wrote:
> Hi,
>
> Can someone please explain the cmake regex matching rules?
>
> The following returns true:
>
> if ("This is a test" MATCHES "test")
>
> I would have expected to have needed something like this to get a match:
>
> if ("This is a test" MATCHES ".*test")
>
> Does cmake always search for a subexpression?  Is there some way to 
> prevent this behaivor?

The regex syntax is documented here:
https://cmake.org/cmake/help/latest/command/string.html#regex-specification

if ("This is a test" MATCHES "^test")

Would match "test" only at the beginning of the input.

Nils


More information about the CMake mailing list