Friday, March 6, 2015

Re: Search pattern while excluding some words

On Fri, Mar 06, 2015 at 01:48:01PM -0600, Tim Chase wrote:
> On 2015-03-06 15:30, John Cordes wrote:
>
> Try
>
> /\(RCMP\|QEII\|SPCA\)\@![A-Z]\{4,}
>
> The \(...\) groups alternatives of things you don't want, and the
> "\@!" asserts that it can't match at the start. It does have some
> edge cases like good MR. WASPCALL (contains "SPCA" which you may or
> may not want) or if you have an exclusion that can begin a legit name.
> You can tighten it a bit with
>
> \<\(RCMP\|QEII\|SPCA\)\@![A-Z]\{4,}\>
>
> Hopefully this gets you where you need to go.

Thanks Tim! I have tried your first suggestion and it
does indeed seem to do what I want. I'll keep a careful
eye out for possible edge problems.

I had looked at the "\@!" construction a bit (obviously
not thoroughly enough) but had thought it would only
exclude those 'words' if they were *immediately* followed
by the search pattern. So I thought it would skip past
something like this: SPCATUVW -- or that it might skip the
whole line if one of the key 'words' was in the line.
Evidently I've misunderstood something, so I'll try
reading about it again.

Thanks again,
John

--
--
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.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment