【发布时间】:2018-02-11 12:58:07
【问题描述】:
我有一个从 Python 中解析 swagger 的 api.json 文件得到的 url。
网址看起来像这样,我想用下划线替换破折号,但只能在大括号内。
10.147.48.10:8285/pet-store-account/{pet-owner}/version/{pet-type-id}/pet-details-and-name
因此,{pet-owner} 将变为 {pet_owner},但 pet-store-account 将保持不变。
我正在寻找一个正则表达式,它允许我执行非贪婪搜索,然后对第一次搜索的每个结果进行搜索替换。
我正在寻找一种 Python re 方法,但如果您能推荐一个 Vim 单行,我也将不胜感激。
预期的最终结果是:
10.147.48.10:8285/pet-store-account/{pet_owner}/version/{pet_type_id}/pet-details-and-name
【问题讨论】:
-
尝试
-(?=[^{}]*})并将每个匹配项替换为_
标签: python regex search vim replace