所以我一直在尝试使用正则表达式(仍在学习)并试图获得这个组合的最后一个值
new avCombination('919712-041','HelloWorld','40.5');
new avCombination('919712-041','HelloWorld','41');
new avCombination('919712-041','HelloWorld','42');
new avCombination('919712-041','HelloWorld','42.5');
new avCombination('919712-041','HelloWorld','43');
new avCombination('919712-041','HelloWorld','44');
new avCombination('919712-041','HelloWorld','44.5');
new avCombination('919712-041','HelloWorld','45');
new avCombination('919712-041','HelloWorld','45.5');
我一直在尝试使用 python,但我陷入了困境
*Updated:*
for values in re.findall('(\d+)(?=\'\);)', listOfCombinations)):
print(values)
但我得到的错误是每个 . 所以意思是等 40.5 只会给我 5 而不是 40.5
我相信我的正则表达式做错了!我应该怎么做才能在这里解决它?
您收到的错误是由于您尝试拆包造成的。请注意,re.findall()
返回一个列表,因此您可能希望执行以下操作:
for i in re.findall(.....):
print(i)
假设您尝试解析的 JS 函数中的最后一个参数始终是 a float
,您可以执行以下操作(其中s
包含所有 JS 函数的字符串在哪里):
list(map(float, re.findall(r'([\d\.]+)(?=\'\);)', s)))
产量:
[40.5, 41.0, 42.0, 42.5, 43.0, 44.0, 44.5, 45.0, 45.5]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句