Conditional regex in vim?

前端 未结 3 962
我在风中等你
我在风中等你 2021-01-03 02:07

Is it possible to do conditional regex (like the one described in http://www.regular-expressions.info/conditional.html) in Vim?

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-03 02:57

    Vim regex does not have this feature, so you will need to use a bit of repetition to create the same behaviour:

    /\(\%(condition\)\@=then\|\%(condition\)\@!else\)
    

    Note that you have to use the condition twice in the Vim version and the lookahead/lookbehind must always be the opposite in the then/else parts otherwise your regex will not be correct.

提交回复
热议问题