
需求:一次匹配,匹配薪水 low 和 high
字段例子:
在正则表达式在线上( https://c.runoob.com/front-end/854 ) 用这个\d+(\.\d+)?能测试通过
但是使用python re.findall(pattern, str)得到结果却不尽如人意
例如:0.7-1 万 /元;我想要得到[0.7, 1]
s = "0.7-1 万 /元" p = "\d+(\.\d+)?" print(re.findall(p, s)) # 得到[0, 7, 1] 求助各位大伙,有无 python 一次匹配可以得到的方法,谢谢啦
1 Mitt 2021 年 3 月 16 日 ([0-9\.]+)(?:-([0-9\.]+))? |
3 chizuo OP |
4 zyb201314 2021 年 3 月 16 日 via Android 这里(?:exp)没有必要吧? 还有例子字符串中除了 float 中有'点', 没有其它单独的'点'.那么直接获取数字和点就 ok 了.如: s="0.7-1 万 /元;" print(re.findall("[\d\.]+" , s)) |
6 HelloViper 2021 年 3 月 17 日 贪婪匹配啊,"[0-9.]{1,}" |