Tuesday, April 26, 2011

How to match A but not B

Benjamen suggested:

/^\%(.*PPD\)\@!.*DEBIT

I was aware of \@!, but the documention warned that .* will match everything
including PPD, before the pattern can find PPD and exclude it. That is why
one must know something about where a string is, to exclude it in a pattern
match, no?

To quote the documentation:

Using "\@!" is tricky, because there are many places where a pattern
does not match. "a.*p\@!" will match from an "a" to the end of the
line, because ".*" can match all characters in the line and the "p"
doesn't match at the end of the line.

Also the order seems wrong to me, but maybe this does not matter? The string,
DEBIT always occrs at the beginning of the line, if it occurs at all, and the
string, PPD always occurs after DEBIT, if it occurs at all. Would the pattern
not be:

/^DEBIT.*\%(PPD\)\@!/

And then there is the problem that .* will match PPD before the exclude
operator \@! can exclude it?

--
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: