Function isEmptyBackreference

  • Returns whether the given backreference will always be replaced with the empty string.

    There are two reasons why a backreference might always be replaced with the empty string:

    1. The referenced capturing group does not consume characters.

      This is the trivial case. If the referenced capturing group never consumes any characters, then a backreference to that group must be replaced with the empty string.

      E.g. /(\b)a\1/

    2. The backreference is not after the referenced capturing group.

      A backreference can only be replaced with a non-empty string if the referenced capturing group has captured text before the backreference is matched. There are multiple reasons why the capturing group might be unable to capture text before a backreference to it is reached.

      • The capturing group might be in a different alternative. E.g. /(a)b|\1/.
      • The backreference might be inside the capturing group. E.g. /(a\1)/.
      • The backreference might be before the capturing group. E.g. /\1(a)/, /(?:\1(a))+/, /(?<=(a)\1)b/

    Parameters

    Returns boolean