Python正则表达式贪婪边界

2024-03-29 07:16:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个

import re

s = """
/* comments */
vector<CWaypoint> Vparam;     // comment
int cValue=2049;                // comment
double param=0.01;              // comment
"""

exp = re.compile(r"(?:\s|\b)(.+?)=(.+?)\b;")
print(exp.findall(s))

我的预期产出是

[(cValue,2049), (param,0.01)]

但是为什么我要在变量名之前获取数据类型,如下所示

[('int cValue', '2049'), ('double param', '0.01')]

为什么即使不贪婪,边界也不起作用


Tags: importre类型paramcommentcommentsintdouble