捕获字符串中的第一个数字(广义)

时间:2017-10-19 19:50:34

标签: regex

我已阅读以下主题,以获取有关在正则表达式中使用前瞻和后瞻的帮助:

return string with first match Regex

Regex lookahead, lookbehind and atomic groups

Regular expression to match last number in a string

考虑以下字符串: string = "About 17 or 18 minutes."

目前我知道如何使用"(\d+)(?!.*\d+)"获取最后一个数字(18),但我在使用单个正则表达式而非{{1}抓取第一个数字出现(17)时遇到问题}或re.findall()方法。

这是我的尝试。我真的希望我离得太远......: 1。re.search()

2. (?<![0-9])\d+(无效......)

我在https://pythex.org/ FYI上测试了这些。非常感谢任何帮助,谢谢!

编辑:我在评论部分已被告知可以使用(\ d +)并仅隔离第一场比赛。谢谢你的帮助。

0 个答案:

没有答案