On Mon, 12 Jun 2006, Charles E Campbell Jr wrote:
Gerald Lai wrote:
On Mon, 12 Jun 2006, Gerald Lai wrote:
On Mon, 12 Jun 2006, Yakov Lerner wrote:
On 6/12/06, Tim Chase <[EMAIL PROTECTED]> wrote:
> I need to match lines using g// (not v//); those lines having
> 'foo' and NOT having /)\s*;/ anywhere in the line. How do I
> write such regex.
Well, there are several ways to go about it. One would be to use
Dr. Chip's "logipat" script:
http://vim.sourceforge.net/scripts/script.php?script_id=1290
LogiPat does wonders. Thanks.
For the record,
:echo LogiPat('"foo"&!"bar"')
produces:
\%(.*foo.*\&^\%(\%(bar\)[EMAIL PROTECTED])*$\)
Yakov
In addition to the regex above, you can also do:
/^\%(.*)\s*;\)[EMAIL PROTECTED]
It's a little shorter, and probably a little faster since the LogiPat
regex does a \%(..\)* for every character position of the line. The
speed is evident for a long line.
It follows the general form of a negative line search for embedded
<search>:
/^\%(.*[<limit0>.*]<search>[.*<limit1>]\)[EMAIL PROTECTED]
For example, to match a line that contains "foo" but does not contain
"bar" between "big" and "tummy":
/\%(.*big.*bar.*tummy\)[EMAIL PROTECTED]
Sorry, I missed the ^ anchor:
/^\%(.*big.*bar.*tummy\)[EMAIL PROTECTED]
Hello!
These two regex's produce different results; I'm using foo and bar
instead of foo and ")\s*;", because its more human readable...
To see the results, use:
vim tst
:set hls
:so pat1
:so pat2
(also, use a fixed font to see this properly in the email)
-- <tst> ----------P1------P2-----
foo * *
bar
foo junk * *
bar junk
junk foo * *
junk bar
foo junk bar *
bar junk foo
-- <pat1> ------------------------
/^\%(bar\)[EMAIL PROTECTED]
-- <pat2> ------------------------
/\%(.*foo.*\&^\%(\%(bar\)[EMAIL PROTECTED])*$\)
----------------------------------
To summarize:
Gerald's pattern (P1, pat1) matches the same three that LogiPat's (P2, pat2)
does,
plus it allows one line that P2 rejects.
In the same context, <pat1> should instead be:
/^\%(.*bar\)[EMAIL PROTECTED]
and both patterns match the same.
--
Gerald