2

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

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

Your approach is pretty close to being correct.

I just used negative lookahead as seen here:

linkend="\([A-Z]\d\+\)">\(\1\)\@!

Comments

0
/<link linkend="\(.*\)">\(\1\)<\/link>

1 Comment

That's the opposite of what I want to match. I want to match not \1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.