On Sat, Nov 14, 2020 at 08:16:26PM EST, Tim Chase wrote:
> On 2020-11-14 16:18, Chris Jones wrote:
[..]
> The "\%(…\)" is the same as the grouping/capturing "\(…\)"
> except, well, it doesn't capture (for later reuse with either "\1",
> "\2", etc, or in an expression with "submatch(2)"). I find that if I
> explicitly use "\(…\)" when I want to capture and use "\%(…\)"
> everywhere else, it's a lot clearer what I intended for capturing and
> what is just there for grouping purposes. In retrospect, I should
> have also used it on the outer grouping since I don't reuse that
> capture
>
> /\\index{\zs\(.*\)\ze}\%(\%(\n.*\)\{,3\}\1\)\@!
> ^ ^
>
> So up to the first "}" finds the "\index{…}" and captures the stuff
> in side for later reuse as "\1". It then has a big group
>
> \%(…\)
>
> that it asserts should not be findable here
>
> \@!
>
In fact (apart from the fact that it works where mine did not...) your
solution is a simplification of my effort. And as an added bonus it
makes it more general catching possible errors outside the targeted
string.
Now since I have in my ~/.vimrc...
| :set ignorecase
| :set smartcase
.. I added the '\C' flag to detect lower/upper case discrepancies:
| \\index{\zs\(.*\)\ze}\%(\%(\n.*\)\{,3\}\1\)\@!\C
> Inside that "assert you can't find this following the \index{…}"
> portion, it looks for "a newline followed by anything, up to three
> times" followed by the stuff we captured earlier ("\1").
>
> If it finds such a match, it's good, so the "you can't find this \@!"
> assertion fails and it doesn't highlight. If it doesn't find such a
> match, it's either because it's too far away (try increasing the "3"
> to some further distance) or because the text is present but doesn't
> match what was inside the \index{…} which could be because of typos
> or because of line-breaks. I.e., if you have
>
> \index{one two three}
> one two
> three
>
> it will highlight it as a non-match because the line-breaks make the
> two different.
>
> > Could you explain further?
>
> Hopefully the explanation above makes enough sense that you can start
> experimenting with it and feel more confident in your abilities to
> use it to bludgeon future problems, bending them to your will. :-D
Nothing hopeful about it! The explanation just works... at least where
I'm concerned. And the good thing is that since this was a real problem
that I had there's a good chance it'll stick...
I played with the proffered regex for a while and I was unable to find
anything wrong with it.
Thanks,
CJ
--
--
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/20201115213923.GA2645%40turki.local.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment