如何找到特定列之间的匹配?

问题描述 投票:0回答:1

示例文本文件中的第7行:

This is an example

这是我的搜索代码:

/example\|an

现在我想捕获从第1列到第11列的子字符串中的匹配:

let myhits = [] | 7s/\%>0cexample\|an\%<12c/\=add(myhits,submatch(0))[-1]/ge | echo myhits

我期望:

myhits = ["an"]  

但发现:

myhits = ["an", "example"] 

我错了什么? 如何在子字符串中捕获匹配项?

string search vim substring
1个回答
2
投票

\|分隔的所有内容都是它自己的分支,因此在您的表达式中,左分支不检查结束列,右分支不检查结束列。您可以使用分组仅分支关键字:\%>0c\(example\|an\)\%<12c

© www.soinside.com 2019 - 2024. All rights reserved.