You could avoid backrefs and make the regexp more maintainable by splitting up three cases with an alternation:

```javascript
return text.replace(/<%(.*?)%>|<\?(.*?)\?)|\{\{(.*)\}\}>/g, function ($0, lessThanPercentFragment, lessThanQuestionMarkFragment, doubleCurlyBraceFragment, offset) {
    var key = '⋖' + offset + '⋗';

    self._templateReplacements[key] = $0;

    return key;
});
```