首页 > 解决方案 > 如何使用正则表达式从带有条件的字符串中提取特定值

问题描述

我的输入字符串 This is Bruno. He is a service shark. Only gets out of the 12.5/11 water to assist you. 13.5/10 terrifyingly good boy

在上面的字符串中,我想提取13.5而不是12.5所以我这样做了:这是代码

    a = re.search(r"\d*\.\d+|\d+\/\'10'", text)
    print(a.group())
# 12.5

我该怎么做?

标签: python-3.xregexnumpy

解决方案


推荐阅读