vim - How to match the white space between two strings in vim?
问题描述
4250682 orderNumber: 60360981400 orderID:4250682
There could be white spaces or tab between "60360981400" and "orderID". How to match those spaces and replace it with only one space?
orderNumber:\d\+.*orderID
This can match the pattern. But how to replace the '.*' with one space?
解决方案
如果只想匹配正则表达式的一部分,可以使用\zs
(start of match) 和\ze
(end of match) 表达式:之前\zs
和之后的匹配部分\ze
将被丢弃,因此内部匹配将被替换:
s/orderNumber: \d\+\zs.*\zeorderID/ /
有关其他详细信息,请参阅:help \zs
。
推荐阅读
- sql - 具有 NULL 值的简单 1:1 映射表的主键?
- php - 使用 XML-RPC 将图像上传到 Odoo12
- html - 如何在 HTML 中使内部 div 元素可滚动(假设正文不是)?
- vue.js - 单个文件组件 - 在从导航栏更改值时重新安装组件
- java - 页面完全加载后读取页面源代码(执行 JavaScript)
- html - Different height and position for col in bootstrap
- mongodb - 向文档 mongodb 添加字段以保留以前的数据
- python-requests - 重试请求而不增加延迟但修复一个(例如:每 30 秒)
- c# - 对 ASP.NET Core 中缺少所需属性的响应
- python - 如何用python在函数内部编写while循环?