python - 关于零宽度断言不支持不确定的长期问题
问题描述
我正在使用 python 的 re 模块的正则表达式来识别此模式下方字符串中的 4 个数字:
合格人数13553人,公司2500人,实际入会人数7187人,公司1722人。
当我使用零宽度断言来识别company is
. 我不知道如何识别最后一个数字,因为有两个相同company is
且(?<="some words")
表达式不支持不定长度。
import re
content = "The number of qualified individuals is 13553, company is 2500, The actual number of individuals joined is 7187,company is 1722."
match_first = re.search("The actual.*\d\\b", content).group()
print(match_first)
match_content = re.search("(?<=company\sis\s)+\d+", match_first).group()
print(match_content)
其实这个方法也可以匹配,但是比较麻烦,总觉得有办法用单个语句匹配最后一个数字。它只匹配数字,其他不匹配,可能是因为我学习了正则表达式。时间太短了,研究了一个晚上的正则表达式还是没找到办法。根据昨晚的了解,可能需要使用递归匹配来解决。我还需要一些时间来完成它,但我认为一定有办法。
解决方案
推荐阅读
- python-3.x - 如何在 chrome 中为 selenium 设置假音频路径?
- javascript - 在哪些情况下您会关心浏览器选择的方向?
- javascript - 用点后 2 位小数分割字符串
- sparql - 出现次数 SPARQL
- haskell - Profunctor 的哪些属性不能进入 Haskell/PureScript?
- html - 将“list-group”放在右侧,而“cards”在左侧,Bootstrap
- makefile - 更改项目目录后Makefile不起作用
- c++ - 如何解决 OJ 上的“运行时错误”
- ruby-on-rails - Bundler 尝试更新 rails 但其版本保持不变
- r - 使用 tidyverse 和 base R 删除列 - 区别