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

Edward Wong wrote:
> Learn a lot more about regexp from this post. Thanks!
>
>> Sorry, I missed the ^ anchor:
>>
>>    /^\%(.*big.*bar.*tummy\)[EMAIL PROTECTED]
>>
>
> Just a question, why it is necessary to have the ^ anchor? Isn't .*
> already includes the characters start from the beginning of the line?
> Sorry if I'm asking a stupid one....

Not a stupid question at all.  [EMAIL PROTECTED] and variants are tricky (IMHO).

Considering:
 /^\%(.*big.*bar.*tummy\)[EMAIL PROTECTED]

First, big.*bar.*tummy can not match quite often!  Just as [EMAIL PROTECTED] 
ordered.
So look at the following two lines:

   big junk bar junk tummy junk foo
   junk bar junk tummy junk foo

Its best to  :set hls  first, so as to see what matches.  Try matching
with and without that leading "^".  With the "^",

   big junk bar junk tummy junk foo    <-- doesn't match
   junk bar junk tummy junk foo        <-- matches

which is what one would expect.  However, without that "^", the pattern
is free to start matching _after_ the start-of-line, and so

   ig junk bar junk tummy junk foo     <-- matches
   junk bar junk tummy junk foo        <-- matches

(I left off the non-matching "b" in the first line).  Thus, both lines
match, which isn't what's wanted, especially considering the regexp
was expected to be used with :g/regex-here/somecmd

Regards,
Chip Campbell

Reply via email to