python - 如何仅在一个单词 Python regex 之后获取特定数字?
问题描述
我有一个这样的字符串:
'$."result"."000182"."200"', '$."result"."000490"."200"', '$."result"."000530"."200"'
我想在之后得到一个数字结果的数组
"result"."[WANTOGETTHISNUMBER]"."200"
我试过这样的(例子)
test_str = "'$.""result"".""000109"".""200""', '$.""result"".""000110"".""200""', '$.""result"".""000111"".""200""', '$.""result"".""000112"".""200""'"
x = re.findall('[0-9]+', test_str)
print(x)
#['000109', '200', '000110', '200', '000111', '200', '000112', '200']
但我希望输出为:['000109', '000110', '000111', '000112']
实现这一目标的正确方法是什么?
解决方案
您可以使用此正则表达式:
>>> re.findall('result\.([0-9]+)', test_str)
['000109', '000110', '000111', '000112']
推荐阅读
- google-analytics - 谷歌优化:“计算的转化率”与“最好的概率”相矛盾
- python - Python - 从文件文件末尾删除最后 2 个字符
- python - Python joblib.Memory - 强制重新计算函数值和/或判断函数值是否来自缓存的方法
- html - 如何将文字放在图像的底部?
- python - Dataframe:添加两个 Daframe 的值
- android - 在 ubuntu 中安装没有 SDK 管理器的 Android NDK
- windows - 为什么 RegisterHotKey 使用 Ctrl-C 会成功?
- assembly - 皮质 r52 架构上的 vstm 是否需要对齐?
- javascript - 使用 jQuery 查找元素并在其中附加值
- node.js - 如何使用 REST API 将数据发送到 websocket 服务器?