Reputation: 1620
I want to validate user-specified version string - to ensure it consists of three period-separated numbers (e.g. 1.20.300
).
But i'm not sure how to write such regex, the code below is just a try:
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 to correctly write required regex?
Thanks.
UPD
My regex also matches 1.2.3.4
, but is should not!
Only three period-separated numbers are possible.
Upvotes: 3
Views: 13798
Reputation: 249464
Dots are special in regex, so you should escape them:
"^([0-9]+)\\.([0-9]+)\\.([0-9]+)$"
Why double-backslash? See here: https://stackoverflow.com/a/4490920/4323
Upvotes: 11