python - 如何在python中使用正则表达式根据值打印界面的整行
问题描述
configuration="""
interface value is 3/40
description eth/1-20-ugb-eth/58
logging event port
ip address 34.5.62
no downtine
interface value is 1/67
description eth/4-56-ugb-eth/78
logging event address
ip address 5.7.8.9
no downtime"""
预期输出:
interface value is 3/40
description eth/1-20-ugb-eth/58
logging event port
ip address 34.5.62
no downtine
这里我需要根据我的值打印接口配置。如果值为 3/40,则需要打印接口的特定配置,但我正在获取所有接口行。任何人都可以帮助我解决这个问题。
我的代码:
re.search(
r"\b{0}(.*)\b".format("interface value{}".format("3/40")) + r"downtime",
configuration,
re.DOTALL,
)
解决方案
推荐阅读
- flutter - 从 TextField 颤振中返回多个数据
- python - 如果满足条件,重复数据框行,并更改一个值的值
- python - Django 显示页面源而不是我的网页
- php - 在 laravel 的表中搜索数据
- python - matplotlib xlim TypeError:“int”和“list”实例之间不支持“>”
- laravel - Laravel 项目中的变量问题
- elasticsearch - 在弹性搜索中结合术语和布尔查询
- javascript - 如何从 VueJS 中的 HTML 模板加载特定组件?
- pandas - 计算 pandas 行中非 NaN 值的数量和长度
- java - 而使用 JAVA 长数字将 TXT 解析为 CSV 正在转换为指数