2009-07-28

Negative Lookbehind in vim

very similar to the last post, but this time for _not_ matching text that is preceded with some other text, and this time using the vim regex engine which is syntactically a little different
/\(Start\)\@<!Date
This will match the 'Date' in 'EndDate' and 'YesterdaysDate' but will not match 'StartDate'

and what the hell, while I'm lookup up vim syntax, here's negative lookahead:
/Start\(Date\)\@!
will match the 'Start' in 'Starting but not in 'StartDate'

Positive lookahead:
/Start\(Date\)\@=
will match the 'Start' in 'StartDate' but not in 'Starting

Positive lookbehind
/\(Start\)\@<=Date
will match the 'Date' in 'StartDate' but not in 'EndDate' and 'YesterdaysDate'

11 comments:

  1. Thanks. I was having trouble a while ago with trying to do lookahead/lookbehind in vim and this was helpful

    ReplyDelete
  2. Thanks for this, I understand how it works now.

    ReplyDelete
  3. This is great, I love the title of your Blog! One question, do you know if there's an easy way to use perl compatible regular expressions?

    ReplyDelete
  4. Thank you for this post, it helped me understand negative lookbehind :)

    ReplyDelete
  5. Excellent post, I like that it is simple and features examples, exactly what I needed

    ReplyDelete
  6. The real necklace of a woman is not her looks but her heart. Visit my site for more interesting offer. Thank you and God bless!

    n8fan.net

    ReplyDelete
  7. :s/\(^\s*\)\@<!\s\+/

    Remove extraneous spaces, but not at the start of the line

    ReplyDelete
  8. Don't forget "very magic" mode \so \you \don't \have \to \escape \everything:

    \v(Start)@<!Date

    ReplyDelete
  9. very nice publish, i certainly love this web site, carry on it online casinos

    ReplyDelete
  10. After research just a few of the weblog posts in your website now, and I really like your manner of blogging. I bookmarked it to my bookmark website checklist and can be checking back soon. Pls take a look at my web page as properly and let me know what you think. casino slots

    ReplyDelete