0

I am trying to construct a regex pattern to match characters inside two # characters. For example:

#abc#bc#cd#

I would like to match abc, bc and cd. The following regex without using magic mode works as expected:

\(#\)\@<=.\{-\}\(#\)\@=

But when I try to use the very magic mode, I can not make the regex pattern right. Here is what I have come up with:

\v(#)\@<=.{-}(#)\@=

and it does not work (matches nothing). Can you point out what is wrong with my regex pattern?

5
  • It's very magic, every character other than 0-9a-zA-Z_ have special meaning. check :h /\v
    – dedowsdi
    Commented May 23, 2019 at 11:53
  • I have read the doc but can find any related part. Do you mean # has special meaning? I can not find the doc on this.
    – jdhao
    Commented May 23, 2019 at 11:59
  • well, why don't you use default magic mode, if it works? BTW: your regex in very magic mode needs to look like this: \v(#)@<=.{-}(#)@= Commented May 23, 2019 at 12:05
  • @ChristianBrabandt, thanks for the regex pattern. I do not know we have to drop the backslash in look around regex in very magic mode. It seems that this is not documented. What do you mean by default magic mode? I use very magic mode because it is more like Perl regex syntax.
    – jdhao
    Commented May 23, 2019 at 12:11
  • of course this is documented: :h /\v Commented May 24, 2019 at 5:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.