Thursday, October 14, 2021

Re: Matching a non-match

Hi all,
On Wed, 13 Oct 2021 at 14:36, Tim Chase <vim@tim.thechases.com> wrote:
>
> On 2021-10-11 23:45, A. Wik wrote:
> > > or if you want to match the entire line, you can use:
> > >
> > > /^\%(\%(exim.input\)\@!.\)*$/
> > >
> > > That breaks down to
> > >
> > > ^ from the start of the line
> > > \%(…\)* zero or more of these things
> > > \%(exim.match\)\@! at each of these places, this can't match
> > > . accept a character here
> > > $ all the way to the end of the line
> > > (no partial line matches, or it would find
> > > ".spool/exim/inpu" (because "exim.input" doesn't yet
> > > match)
> >
> > Can you clarify the function of the dot? It appears that without
> > it, it finds only empty lines. With it, it finds any line not
> > matching "exim.input", including empty lines.
>
> Sorry for the late reply. The "." is what lets the regex move
> forward, roughly stating ".*" but at each of those "." locations,
> before we accept that location, we assert that "exim.match" can't
> match at that particular character.
>
> this line contains exim match here
>
> when the regex engine gets to the "e" in "exim match", the \@!
> assertion fails, so the regex doesn't match that line, but on a line
> like
>
> hello
>
> it starts at the beginning. /exim.match/ doesn't match there so the
> "." accepts the "h", moving to the next char. /exim.match/ doesn't
> match there either, so the "." accepts the "e". Repeat until it gets
> to the end, having asserted that each ".", no /exim.match/ exists.
>
> Hope that helps make a bit of sense of it?

Yes, I think so. Is it because \@! is zero-width that it must be
paired with something (eg. ".") that does have width?

And it matches an empty line because of the \%( ... \)*?

-aw

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CALPW7mTVWaRd026iULVbQXbnPbhBKOtymcz_NiHP4NPPbk_ptA%40mail.gmail.com.

No comments:

Post a Comment