Reputation: 10531
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?
Upvotes: 0
Views: 326
Reputation: 2597
If you want to match only a part of the regex expression, you can use \zs
(start of match) and \ze
(end of match) expressions: the matching part before \zs
and after \ze
will be discarded, thus the inner match will be replaced:
s/orderNumber: \d\+\zs.*\zeorderID/ /
For additional details, see :help \zs
.
Upvotes: 3
Reputation: 158
In order to replace all instances of consecutive whitespaces with one space, you can use the whitespace metacharacter \s
, as in :s/\s\+/ /g
.
Or look into grouping and backreferences: :s/\(orderNumber: \d\+\).*\(orderID\)/\1 \2/
http://vimregex.com/ will explain all of the above and a lot more.
Upvotes: 0