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'

12 Comments:

Anonymous Anonymous said...

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

August 28, 2012 at 11:36 PM  
Anonymous Anonymous said...

Thanks for this, I understand how it works now.

January 26, 2013 at 1:07 AM  
Blogger Unknown said...

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?

November 7, 2013 at 3:40 AM  
Anonymous Anonymous said...

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

March 25, 2014 at 4:25 AM  
Anonymous Anonymous said...

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

June 21, 2014 at 12:34 AM  
Blogger Torgeir said...

Succinct, awesome.

July 4, 2014 at 6:14 PM  
Blogger joy said...

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

May 5, 2015 at 6:50 PM  
Anonymous Anonymous said...

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

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

January 12, 2016 at 10:24 PM  
Blogger Unknown said...

Reading your article is such a privilege. It does inspire me, I hope that you can share more positive thoughts. Visit my site too. The link is posted below.

n8fan.net

www.n8fan.net

April 26, 2016 at 12:23 PM  
Anonymous Anonymous said...

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

\v(Start)@<!Date

May 24, 2016 at 8:27 PM  
Blogger nikkolayebba said...

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

June 20, 2018 at 12:39 AM  
Blogger moshrabbi121 said...

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

June 20, 2018 at 6:09 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home