Thursday, November 12, 2020

regex to find where 'sample text' is not followed by 'sample text' a couple of lines down

I am proofreading a document where a few words occur on one line and the
same exact words are replicated two lines down.

Here's a sample:

| ```{=latex}
| \index{Text that must occur twice}
| ```
| **2507. Text that must occur twice.** ... etc.

I found that it's easy to highlight such occurrences using (e.g.):

| /\\index{\(.*\)}\n```\n\*\*\d\+\. \1 " (1)

Now I noticed that once in a while the repeated text is not the same as
the text inside the curly brackets (i.e. in the \latex{...} command).

Trouble is... there are over three thousand such occurrences...

Rather than highlighting the instances where the two strings match
I would prefer to have vim highlight the ones where they don't.

In order to find them I tried:

| /\\index{\(.*\)}\n```\n\*\*\d\+\. \@<!\1 " (2)

The '\@<!' as I understand it means that my search pattern will match
everything up to and including the space... followed by something that
differs from the current value of the '\1' back reference.

For instance it should match/highlight something like this:

| ```{=latex}
| \index{Text that must occur twice}
| ```
| **2507. Text that must oKKur twice.** ... etc.

Unfortunately it does not.

Is this caused by a flaw in my logic or is it my misunderstanding of the
way '\@<!' works...?

What would be the right way to detect such discrepancies?

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/20201112234256.GB9509%40turki.local.

No comments: