regex以匹配版本号



大家好,我已经解析了要匹配的数据。

我列出了我解析过的两个字符串:

technologytitle=technologytitle.lower()
vulntitle=vulntitle.lower()
ree1=re.split(technologytitle, vulntitle)

这会产生以下内容:

['nmultiple cross-site scripting (xss) vulnerabilities in', '9.0.1 and earliernnnnn']

我现在正在尝试编写re.match,以将第二个值与相匹配

ree2=re.match(r'^[0-9].[0-9]*$', ree1[1])
print("ree2 {}".format(ree2))

然而这是返回CCD_ 1。

有什么想法吗?感谢

不清楚是否需要整个字符串或单独的部分,但可以在没有^$的情况下同时执行这两个操作

import re
regex = r'((?P<major>d+).(?P<minor>d+).(?P<patch>d+))'
s = '9.0.1 and earliernnnnn'
matches = re.search(regex, s)
print(matches.group(0))
for v in ['major', 'minor', 'patch']:
print(v, matches.group(v))

输出

9.0.1
major 9
minor 0
patch 1

我使用了这个,它对我有效,因为美元符号意味着模式的结束,而你的模式没有以0-9之间的数字结束,那么它就不会给你

regexPattern = "[0-9].*[0-9]"

最新更新