Wednesday, October 3, 2012

[Rephrased] Problem with a regular expression in Vim

Hi all,

Sorry for the previous mail where my ambiguous expression led to a
somewhat time-wasting discussion. Thanks for the guys who tried to
help. Here is the rephrased version.

I what to use command :match to highlight some text, which is
free-form and thus can not be enumerated. The text is always
surrounded by a pair of "==". I need a regex to match the text.

In the following example, what I want to be highlighted is "aaa" and "bbb"

xxx==aaa==cccddd==bbb==yyy

In the following example, what I want is "a", "c", "e" and "g"

x==a==b==c==d==e==f==g==y

In a nutshell, taking the second example to illustrate, it'd be better
to consider it as "x(a)b(c)d(e)f(g)y" and then highlight the elements
between the pair of "()" but not the ones between ")" and "(" or the
"()" themselves. BTW, there is no alternative result. Because you
can always start from the beginning of the line to make sure that
imaginary substitution is unique.

And, I knew that using /==[^=]\{-}==/ or something similar can offer
the _approximate_ result, however the surroundings "==" are not
excluded as expected.

Ben Fritz and Chris Jones correctly pointed out that \zs\ze is useless
here because it makes the latter "==" constituting another valid
match, by which every element between the pair of "==" will be
highlighted.

Provided that I'd like to insist on using :match, is it possible to
write a regex to meet my requirement?

(According to Jones, due to the mechanism of regex engine, it's highly
improbable...)

Thanks.

Best,
Xell

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