Regular expression version in CMake

I want to check the user-supplied version string to make sure it is three period-separated numbers ( e.g. 1.20.300

).
But I'm not sure how to write a regex like this, the code below is just an attempt:

if( PROJECT_VERSION MATCHES "([0-9]+).([0-9]+).([0-9+])" )
    message( "NOTE: Valid version string" )
else()
    message( FATAL_ERROR "Invalid version string" )
endif()

      

So how do you write the required regex correctly?
Thank.

UPD
My regex also matches 1.2.3.4

, but shouldn't!
Only three periods are possible, separated by a dot.

0


source to share


1 answer


Dots are special in regular expressions, so you should avoid them:

"^([0-9]+)\\.([0-9]+)\\.([0-9]+)$"

      



Why double backslash? See here: fooobar.com/questions/468978 / ...

+4


source







All Articles