正则表达式模式从字符串中提取版本号 [英] Regex pattern to extract version number from string
本文介绍了正则表达式模式从字符串中提取版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从字符串中提取版本号.
I want to extract version number from string.
a string = "Tale: The Secrets 1.6"
b string=" The 34. Mask 1.6.98";
所以对于版本号是1.6,对于b是1.6.98
So for a version number is 1.6 and for b is 1.6.98
推荐答案
\d+(\.\d+)+
\ d +
:一位或多位数字 \.
:一分(\.\ d +)+
:一个或多个点数字出现
\d+
: one or more digits
\.
: one point
(\.\d+)+
: one or more occurences of point-digits
会找到
2.5
3.4.567
3.4.567.001
但找不到
12
3.
.23
如果您要排除十进制数字(例如 2.5
),并且希望版本号至少包含3个部分,则可以使用这样的量词
If you want to exclude decimal numbers like 2.5
and expect a version number to have at least 3 parts, you can use a quantifier like this
\d+(\.\d+){2,}
在逗号后,您可以指定最多出现的次数.
After the comma, you can specify a maximum number of ocurrences.
这篇关于正则表达式模式从字符串中提取版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文