Reputation: 11321
I'm trying to match XML entries where the link doesn't correspond to the link text, like this:
<link linkend="G431">X595</link>
but NOT links where the link text is correct, like this:
<link linkend="G431">G431</link>
How can I write a vim regex to match the first of those? I've tried things like:
linkend="\([A-Z]\d\+\)">[^\1]
and
linkend="\([A-Z]\d\+\)">^\(\1\)\@!
but I can't quite seem to get anything to work. Basically I'm trying to say "find a link where the link text does NOT equal the link location."
Upvotes: 2
Views: 241
Reputation: 4640
Your approach is pretty close to being correct.
I just used negative lookahead as seen here:
linkend="\([A-Z]\d\+\)">\(\1\)\@!
Upvotes: 1
Reputation: 53614
In your second variant you have …\)">^\(\1\)\@!…
. You don’t need caret here: it means itself (caret) in this position (usually it means “start of line”, but not there: see :h /^
). Neither you need parenthesis (they do not harm, but they are not needed):
linkend="\([A-Z]\d\+\)">\1\@!
. Negation is expressed via !
(positive look-ahead is \@=
). In [^\1]
variant you match any character, but backslash, ASCII one and line break: collections do not support back references and even if they did support it it would be illogical for a collection to match more then one character (so if they did it would pull a set of characters present in a matched text).
Upvotes: 4