【问题标题】:lookarounds positive negative lookbehind lookahead环顾 正面 负面 回望 前瞻
【发布时间】:2016-09-07 02:19:57
【问题描述】:

在谷歌上搜索 vsvim 前瞻或后视以及wiki 之后,我似乎无法弄清楚它是否支持前瞻或后视(正面或负面)以及如何使用它们。

我尝试了一些不同的syntaxes,例如\ze\@=(?<=let \w\+)(\(?<=let \w\+\)(,我在vim answers 上看到过,但它们似乎都没有在vs vim 中进行匹配(也没有替代)

如何在 VsVim 中进行环视?

【问题讨论】:

  • 这是您要找的吗? link
  • 没有测试,但是是的,这似乎是我想要的
  • 太好了,希望它有效。告诉我。

标签: vsvim


【解决方案1】:

我想从 @briansrls 扩展 excellent answer。我一直在寻找一种更强大的解决方案,可以处理多词短语、通配符(用于短语之间的潜在间隙)和替代方案(即模式):

没有通配符:

  Positive Lookahead:  \(find this\)\(followed by this\|or that\)\@=
  Negative Lookahead:  \(find this\)\(not followed by this\|or that\)\@!
  Positive Lookbehind: \(preceded by this\|or that\)\@<=\(find this\)
  Negative Lookbehind: \(not preceded by this\|or that\)\@<!\(find this\)

使用通配符:

  Positive lookahead:  \(find this\)\(.*\(eventually followed by this\|or that\)\)\@=
  Negative lookahead:  \(find this\)\(.*\(not eventually followed by this:\|or that\)\)\@!
  Positive lookbehind: \(\(eventually preceded by this\|or that\).*\)\@<=\(find this\) 
  Negative lookbehind: \(\(not eventually preceded by this\|or that\).*\)\@<!\(find this\)

注意:对于通配符版本,额外的括号是必需的,以便通配符从替代组中排除,但包含在环顾组中。这可以防止为每个备选方案复制通配符。也可以使用\zs 和\ze 来避免多余的括号,但我发现这种方法更直观一些。

更多信息:

更新:目前看来,\zs 和 \ze 在 VsVim 中是 not yet implemented。

【讨论】:

    【解决方案2】:

    对于任何新人,我会将这个链接的内容复制到这里以备将来使用:

    http://ssiaf.blogspot.ru/2009/07/negative-lookbehind-in-vim.html

    /\(Start\)\@<!Date
    

    这将匹配“EndDate”和“YesterdaysDate”中的“Date”,但不会匹配“StartDate”

    /Start\(Date\)\@!
    

    将匹配 'Starting 但不匹配 'StartDate' 中的 'Start'

    /Start\(Date\)\@=
    

    将匹配“StartDate”中的“Start”,但不匹配“Starting”中的“Start”

    /\(Start\)\@<=Date
    

    将匹配“StartDate”中的“Date”,但不匹配“EndDate”和“YesterdaysDate”中的“Date”

    【讨论】:

    • 可能适用于 Vim,但不适用于 VsVim v.2.1.1.0(使用 Visual Studio 2015 时)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 2018-06-29
    • 2016-05-19
    • 1970-01-01
    • 2016-07-27
    • 2012-12-13
    相关资源
    最近更新 更多