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


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:


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

  • It's very magic, every character other than 0-9a-zA-Z_ have special meaning. check :h /\v – dedowsdi May 23 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 May 23 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(#)@<=.{-}(#)@= – Christian Brabandt May 23 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 May 23 at 12:11
  • of course this is documented: :h /\v – Christian Brabandt May 24 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.