首页 > 解决方案 > 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?

标签: vim

解决方案


如果只想匹配正则表达式的一部分,可以使用\zs(start of match) 和\ze(end of match) 表达式:之前\zs和之后的匹配部分\ze将被丢弃,因此内部匹配将被替换:

s/orderNumber: \d\+\zs.*\zeorderID/ /

有关其他详细信息,请参阅:help \zs


推荐阅读