Wednesday, October 3, 2012

Re: Problem with a regular expression in Vim

* Xell Liu <xell.liu@gmail.com> [121003 03:18]:
> Hi Paul,
>
> By extraction I mean that what I need to match is only the contents
> without the surroundings "==" (i.e. extracting "aaa" from "==aaa==").
>
> I certainly know that I could use \(\) to get the contents afterwards.
> But I want to know how to match the contents solely. For example,
> while using :match command, the surroundings outside \(\) will be
> always highlighted according to your suggestion.
>
> >> In fact, by pseudocode I think I can put my requirement like this:
> >>
> >> 1. Search for the first pair of "==" from the beginning location where
> >> the search starts.
> >> 2. Extract the contents in the pair of "==" as the first match result.
> >> 3. Disable/Invalidate/Remove the matched contents with its "==" surroundings.
> >> 4. Repeat from 1. until reaching the end of the search range.
> >>
> >> So, is it possible to do that by regular expression? I'm not very
> >> familiar with the concepts of greedy/non-greedy or zero-match (like
> >> the queer things of \@! or \@<= etc.) or . Will they help?

(Please don't top-post.)

The meaning of the terms "extract" and "disable/invalidate/remove" in 2 and
3 above is unclear to me (and apparently others on this list).

It is not clear what your criteria are for what is supposed to match and
what isn't. You seem to want the effects of \zs and \ze, which exclude
the "==" from the part of the text that is considered to match (i.e.
what is highlighted if 'hls' is on, and what would be replaced with
:s//something/). But you say you want to match the "aaa" and "ddd", but
not the "bbbccc". What is not clear is what strings between pairs of
"==" you want to match.

Is it alternating matches, so that if "==" occurs seven times, you match
the first, third, and fifth inner strings, like this:

a==b==c==d==e==f==g==h

would match b, d, and f?

Do you want exactly what is done by /==\zs[^=]\{-}\ze==/ except that you
want to start looking for the next match (e.g. with the normal mode
command 'n') _after_ the trailing "==" of the previous match?

Side note: In the given regex, because you are matching [^=] between
==, there is no difference between greedy and non-greedy. The
expression could be /==\zs[^=]*\ze==/.

...Marvin

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

No comments:

Post a Comment