Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Version regular expression in CMake

Tags:

regex

cmake

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.

like image 386
eraxillan Avatar asked Apr 07 '26 12:04

eraxillan


1 Answers

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

like image 166
John Zwinck Avatar answered Apr 09 '26 09:04

John Zwinck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!