Vim:我如何搜索后面没有另一个词的词? [英] Vim: How do I search for a word which is not followed by another word?

查看:43
本文介绍了Vim:我如何搜索后面没有另一个词的词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常基本的问题,我正在尝试在 Vim 中编写一个正则表达式来匹配任何以 "abc " 开头的短语,直接后跟除 "defg" 以外的任何短语.

Pretty basic question, I'm trying to write a regex in Vim to match any phrase starting with "abc " directly followed by anything other than "defg".

我使用 "[^defg]" 匹配除 d、e、f 或 g 之外的任何单个字符.

I've used "[^defg]" to match any single character other than d, e, f or g.

我的第一直觉是尝试 /abc [^\(defg\)]/abc [^\<defg\>] 但都没有那些作品.

My first instinct was to try /abc [^\(defg\)] or /abc [^\<defg\>] but neither one of those works.

推荐答案

这是搜索字符串.

/abc \(defg\)\@!

您正在寻找的概念称为否定前瞻断言.在 vim 中试试这个以获取更多信息:

The concept you're looking for is called a negative look-ahead assertion. Try this in vim for more info:

:help \@!

这篇关于Vim:我如何搜索后面没有另一个词的词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆