CMake中的版本正则表达式

编程入门 行业动态 更新时间:2024-10-22 14:44:15
本文介绍了CMake中的版本正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想验证用户指定的版本字符串-确保它由三个以句点分隔的数字(例如1.20.300 )组成。 但是我不确定如何编写这样的正则表达式,下面的代码只是一个尝试:

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 我的正则表达式也匹配 1.2.3.4 ,但不应该! 只能使用三个以句点分隔的数字。

UPD My regex also matches 1.2.3.4, but is should not! Only three period-separated numbers are possible.

推荐答案

点在正则表达式中是特殊的,因此应转义它们:

Dots are special in regex, so you should escape them:

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

为什么要使用双反斜杠?看到这里: stackoverflow/a/4490920/4323

Why double-backslash? See here: stackoverflow/a/4490920/4323

更多推荐

CMake中的版本正则表达式

本文发布于:2023-11-28 15:33:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642974.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:版本   正则表达式   CMake

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!