Wednesday, October 13, 2021

Re: Matching a non-match

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?

-tim


--
--
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/20211013093623.413af4c8%40bigbox.attlocal.net.

No comments: