A.4 Backreferences

Backreferences are used to overcome the problem that one match has no knowledge of its previous match, appearing as a pair of a subexpression and a \number referencing to that subexpression.

Find all repeated words (often typos):

  • This is a block of of text, several words here are are repeated, and and they should not be.

Another example with html data where we want to match all normal header tags, note that the last pair <h2>...<h3> is invalid:

Backreferences is particularly useful when performing replace operations.