Sunday, April 24, 2011

Re: How to match A but not B

On 2011-04-24, howard Schwartz wrote:
> I want to match lines that contain the word, DEBIT but do not contain the
> word PPD. How to I construct a pattern that will do this?
>
> For example the pattern should exclude a line like,
>
> DEBIT, this is a line with PPD in it
>
>
> But the pattern should match:
>
> DEBIT, this is a line without a certain word in it.

I don't use patterns with NOT clauses often enough to remember how
to construct them, and I don't find the Vim manual very helpful in
their regard, so I've loaded Charles Campbell's LogiPat plugin,

http://vim.sourceforge.net/scripts/script.php?script_id=1290

to help me with them. The command,

:LogiPat "DEBIT"&!"PPD"

produces the pattern

\%(.*DEBIT.*\&^\%(\%(PPD\)\@!.\)*$\)

which illustrates well why I have difficulty constructing such
patterns manually. To understand what it's doing, see

:help /\&
:help /\@!

Those are the primary operators in that expression. \%( and \) are
for grouping. The other components should be familiar.

HTH,
Gary

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: